[llvm-bugs] [Bug 42776] New: Incorrect code generation for inlined functions when -Oz flags are specified

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jul 26 07:51:45 PDT 2019


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

            Bug ID: 42776
           Summary: Incorrect code generation for inlined functions when
                    -Oz flags are specified
           Product: clang
           Version: 9.0
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: joan.lluch at icloud.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Consider the following code:

inline int inlinedFunc( int a, int ammount )
{
  if ( (ammount -= 8) >= 0 )
    a = a >> 8;

  while ( ammount-- )
    a >>= 1;

  return a;
} 

int useInlined( int a, int b)
{
  return inlinedFunc(a,b);
}

The above is compiled like this for the x86 architecture when -Oz is specified:

; ModuleID = 'main.c'
source_filename = "main.c"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.12.0"

; Function Attrs: minsize nounwind optsize uwtable
define i32 @useInlined(i32 %a, i32 %b) local_unnamed_addr #0 {
entry:
  %call = tail call i32 @inlinedFunc(i32 %a, i32 %b) #2
  ret i32 %call
}

; Function Attrs: inlinehint minsize nounwind optsize uwtable
declare i32 @inlinedFunc(i32, i32) local_unnamed_addr #1

attributes #0 = { minsize nounwind optsize uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "min-legal-vector-width"="0"
"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"="penryn"
"target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { inlinehint minsize nounwind optsize uwtable
"correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false"
"less-precise-fpmad"="false" "min-legal-vector-width"="0"
"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"="penryn"
"target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #2 = { minsize optsize }

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

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{!"clang version 9.0.0 (https://github.com/llvm/llvm-project.git
bd1c1ad50f7ae95068151c492fefd1f8c3a37e6d)"}


Since the -Oz flag is specified, it is expected and correct that the funciton
is not effectivelly inlined. So "inlineFunc" is called as a normal funcion
(this is ok). However, the "inlinedFunc" is declared but not defined. Its
definition should not be removed from the output because it is actually called
by "useInlined" and not defined elsewhere (not ok).

Joan

-- 
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/20190726/77996418/attachment-0001.html>


More information about the llvm-bugs mailing list