[llvm-bugs] [Bug 36236] New: clang generates wrong module by removing un-inlined function body in -O0

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Feb 5 01:47:25 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36236

            Bug ID: 36236
           Summary: clang generates wrong module by removing un-inlined
                    function body in -O0
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mohammed.agabaria at intel.com
                CC: llvm-bugs at lists.llvm.org

examine the following code:

test.c:

inline int foo(int idx, int* A) {
  A[idx] = 0;
  return A[idx] + 7;
}

int main(int argc, char* argv[]) {
  int A[100];
  int As = foo(0, A);
  printf("d = %d\n", As);
  return 0;
}

main calls foo which have an inline hint.
when compiling in clang -O0 the module won't have foo anymore although it still
have the call to foo (later this cause the linker to fail of course).

LLVM IR: (./clang -O0 test.c -emit-llvm -S -o a.ll)
Notice that main still call foo but there is no definition for foo in the
module.

; ModuleID = 'test.c'
source_filename = "test.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str = private unnamed_addr constant [8 x i8] c"d = %d\0A\00", align 1

; Function Attrs: noinline nounwind optnone uwtable
define i32 @main(i32 %argc, i8** %argv) #0 {
entry:
  %retval = alloca i32, align 4
  %argc.addr = alloca i32, align 4
  %argv.addr = alloca i8**, align 8
  %A = alloca [100 x i32], align 16
  %As = alloca i32, align 4
  store i32 0, i32* %retval, align 4
  store i32 %argc, i32* %argc.addr, align 4
  store i8** %argv, i8*** %argv.addr, align 8
  %arraydecay = getelementptr inbounds [100 x i32], [100 x i32]* %A, i32 0, i32
0
  %call = call i32 @foo(i32 0, i32* %arraydecay)
  store i32 %call, i32* %As, align 4
  %0 = load i32, i32* %As, align 4
  %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8
x i8]* @.str, i32 0, i32 0), i32 %0)
  ret i32 0
}

declare i32 @foo(i32, i32*) #1

declare i32 @printf(i8*, ...) #1

attributes #0 = { noinline nounwind optnone uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "no-frame-pointer-elim"="true"
"no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false"
"no-jump-tables"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false"
"disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-nans-fp-math"="false"
"no-signed-zeros-fp-math"="false" "no-trapping-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false"
"use-soft-float"="false" }

!llvm.module.flags = !{!0}
!llvm.ident = !{!1}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 7.0.0 (trunk 324213)"}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180205/00ecfb17/attachment-0001.html>


More information about the llvm-bugs mailing list