jeudi 1 décembre 2016

How comes the basic block does not have terminator?

So I am trying to generate code for an if statement but I am receiving "Basic Block in function (function_name) does not have terminator! label %then"

But if check the code generated it seems like the terminators are there for each block.

define void @M4_Main_main() {
%1 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RString)
%2 = bitcast i8* %1 to %struct.TString*
%3 = getelementptr %struct.TString, %struct.TString* %2, i32 0, i32 1
store i32 22, i32* %3
%4 = getelementptr %struct.TString, %struct.TString* %2, i32 0, i32 2
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @0, i32 0, i32 0), i8** %4
%5 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RIO)
%6 = bitcast i8* %5 to %struct.TIO*
%7 = call %struct.TIO* @M2_IO_out(%struct.TIO* %6, %struct.TString* %2)
br i1 true, label %then, label %else

then:                                             ; preds = %0
                                              ; No predecessors!
%9 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RString)
%10 = bitcast i8* %9 to %struct.TString*
%11 = getelementptr %struct.TString, %struct.TString* %10, i32 0, i32 1
store i32 12, i32* %11
%12 = getelementptr %struct.TString, %struct.TString* %10, i32 0, i32 2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @1, i32 0, i32 0), i8** %12
%13 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RIO)
%14 = bitcast i8* %13 to %struct.TIO*
%15 = call %struct.TIO* @M2_IO_out(%struct.TIO* %14, %struct.TString* %10)
br label %ifcont

else:                                             ; preds = %0
                                              ; No predecessors!
br label %ifcont

ifcont:                                           ; preds = %16, %8
%iftmp = phi i32 [ <null operand!>, %8 ], [ <null operand!>, %16 ]
%17 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RString)
%18 = bitcast i8* %17 to %struct.TString*
%19 = getelementptr %struct.TString, %struct.TString* %18, i32 0, i32 1
store i32 22, i32* %19
%20 = getelementptr %struct.TString, %struct.TString* %18, i32 0, i32 2
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @2, i32 0, i32 0), i8** %20
%21 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RIO)
%22 = bitcast i8* %21 to %struct.TIO*
%23 = call %struct.TIO* @M2_IO_out(%struct.TIO* %22, %struct.TString* %18)
br i1 false, label %then1, label %else2

then1:                                            ; preds = %ifcont
                                              ; No predecessors!
br label %ifcont3

else2:                                            ; preds = %ifcont
                                              ; No predecessors!
%26 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RString)
%27 = bitcast i8* %26 to %struct.TString*
%28 = getelementptr %struct.TString, %struct.TString* %27, i32 0, i32 1
store i32 12, i32* %28
%29 = getelementptr %struct.TString, %struct.TString* %27, i32 0, i32 2
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @3, i32 0, i32 0), i8** %29
%30 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RIO)
%31 = bitcast i8* %30 to %struct.TIO*
%32 = call %struct.TIO* @M2_IO_out(%struct.TIO* %31, %struct.TString* %27)
br label %ifcont3

ifcont3:                                          ; preds = %25, %24
%iftmp4 = phi i32 [ <null operand!>, %24 ], [ <null operand!>, %25 ]
%33 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RString)
%34 = bitcast i8* %33 to %struct.TString*
%35 = getelementptr %struct.TString, %struct.TString* %34, i32 0, i32 1
store i32 4, i32* %35
%36 = getelementptr %struct.TString, %struct.TString* %34, i32 0, i32 2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @4, i32 0, i32 0), i8** %36
%37 = call i8* @__lcpl_new(%struct.__lcpl_rtti* @RIO)
%38 = bitcast i8* %37 to %struct.TIO*
%39 = call %struct.TIO* @M2_IO_out(%struct.TIO* %38, %struct.TString* %34)
ret void
}

I read that to terminate a block it should have either a return or a branch and all my blocks do have such a statement. What could be the problem here ?

CASE, IFElse, or SWITCH Powershell to change output of Get-WmiObject

I have the following code that works as a stand-alone query:

$Type = (Invoke-Command -ComputerName $Computer -ScriptBlock { Get-WmiObject -Class Win32_ComputerSystem  | Select-Object -ExpandProperty Manufacturer })

    switch -regex ($Type) 
    { 
        "VMw.+" {"VM"} 
        default {"Physical"}
    }

I want to add the switch command within the Invoke command instead of a variable (dropping the $Type variable) so that it can be run against multiple computers, how can this be accomplished, I am not determined to use Switch to accomplish the end result?

Passing data from inside if to condition else if

int c = 2;
int a = 1;


if(a==1){
   if(b=2)
     {c = 3;} 
   else 
     {d = 4;}
}

else if(c==3){
system.out.println("Success");
}

else{
system.out.println("Failed")}

I want display "Success" but value c is 2 .. not 3 .. How i can pass data from if to be condition else ?

Swift: "Where" vs "If"

Is there any difference between these two syntaxes? If not, any benefit?

if let userName = userNameTextField.text where userName.characters.count > 0,
        let password = passwordTextField.text where password.characters.count > 0,
        let confirmation = confirmationTextField.text where confirmation == password
    else {
        return false
    }

and:

if userNameTextField.text?.characters.count > 0 &&
        passwordTextField.text?.characters.count > 0 &&
    confirmationTextField.text == passwordTextField.text
    {
        return false
    }

`if' is not matched

I am getting the below error when trying to execute the script ./LIFNR_error_alert.s

./LIFNR_error_alert.sh[8]: 0403-057 Syntax error at line 14 : `if' is not matched.

Code :

has_error_occured=false
if [ $current_interval_count -gt $last_interval_count ]
then
has_error_occured=true
new_error_count=$((current_interval_count - last_interval_count))
fi
if [ $has_error_occured ];then
    grep 'Required input field LIFNR' /data/logs/errorWMS-SAP_LV_20_02.log > /u/peima01/LIFNR_alert/script/all_errors_in_file.txt
    tail  -$new_error_count /u/peima01/LIFNR_alert/script/all_errors_in_file.txt > /u/peima01/LIFNR_alert/script/errors_to_mail.txt
    cat /u/peima01/LIFNR_alert/script/Template.txt > /u/peima01/LIFNR_alert/script/mail_body.txt
    cat /u/peima01/LIFNR_alert/script/errors_to_mail.txt >> /u/peima01/LIFNR_alert/script/mail_body.txt
    (cat /u/peima01/LIFNR_alert/mail_body.txt)| mail -s "List of Vendors not receiving IDOC" xyz@gmail.com
else
    echo " No errors logged" xyz@gmail.com
fi

Can you guys show where i am going wrong ?

jinja : using variable from for loop inside if statement

I am trying to use a vraiable in a "if" statement, this variable is defined in a for loop, but I cannot get it to works, here is a code excerpt :



I think the code is self explanatory, if not please ask !

I know my code is not the best looking one, if you have any advices I'd be happy to take them !

Break if statement c++ error

I'm writing linear and quadratic probing hash table program.

This is a for-loop I used for linear probing function and it works perfectly fine.

//when there's a collision increase i by 1 until finding empty slot
       for(i = (hashVal % tableSize+1) % tableSize; i <tableSize; i++)
           if(a[i] == -1){
               a[i] = hashVal;
               break;
           }

so I wrote a for loop again in quadratic probing function to deal with collision

//when there's a collision increase i by i^2
    j = 0;

    for(i=((hashVal % tableSize+1) % tableSize); i < tableSize; i++)
        j = i^2;
        if(a[j] == -1){
            a[j] = hashVal;
            break;
        }

But when I compile quadratic probing, I'm getting this error

error: 'break' statement not in loop or switch statement

I am really confused why it causes error in the second one while it is fine in linear probing. Could anyone explain why? Thank you.