r240735 - [CodeGen] Restrict isTriviallyRecursive to predefined lib functions forwarding to lib functions

David Majnemer david.majnemer at gmail.com
Thu Jun 25 16:50:41 PDT 2015


Author: majnemer
Date: Thu Jun 25 18:50:40 2015
New Revision: 240735

URL: http://llvm.org/viewvc/llvm-project?rev=240735&view=rev
Log:
[CodeGen] Restrict isTriviallyRecursive to predefined lib functions forwarding to lib functions

isTriviallyRecursive is only supposed to guard functions part of the
implementation.

This fixes PR23953.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/pr9614.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=240735&r1=240734&r2=240735&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jun 25 18:50:40 2015
@@ -1425,7 +1425,7 @@ namespace {
         return false;
       }
       unsigned BuiltinID = FD->getBuiltinID();
-      if (!BuiltinID)
+      if (!BuiltinID || !BI.isLibFunction(BuiltinID))
         return true;
       StringRef BuiltinName = BI.GetName(BuiltinID);
       if (BuiltinName.startswith("__builtin_") &&
@@ -1454,7 +1454,12 @@ CodeGenModule::isTriviallyRecursive(cons
     Name = FD->getName();
   }
 
-  FunctionIsDirectlyRecursive Walker(Name, Context.BuiltinInfo);
+  auto &BI = Context.BuiltinInfo;
+  unsigned BuiltinID = Context.Idents.get(Name).getBuiltinID();
+  if (!BuiltinID || !BI.isPredefinedLibFunction(BuiltinID))
+    return false;
+
+  FunctionIsDirectlyRecursive Walker(Name, BI);
   Walker.TraverseFunctionDecl(const_cast<FunctionDecl*>(FD));
   return Walker.Result;
 }

Modified: cfe/trunk/test/CodeGen/pr9614.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pr9614.c?rev=240735&r1=240734&r2=240735&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/pr9614.c (original)
+++ cfe/trunk/test/CodeGen/pr9614.c Thu Jun 25 18:50:40 2015
@@ -4,26 +4,35 @@ extern void foo_alias (void) __asm ("foo
 inline void foo (void) {
   return foo_alias ();
 }
-extern void bar_alias (void) __asm ("bar");
-inline __attribute__ ((__always_inline__)) void bar (void) {
-  return bar_alias ();
+extern int abs_alias (int) __asm ("abs");
+inline __attribute__ ((__always_inline__)) int abs (int x) {
+  return abs_alias(x);
 }
 extern char *strrchr_foo (const char *__s, int __c)  __asm ("strrchr");
 extern inline __attribute__ ((__always_inline__)) __attribute__ ((__gnu_inline__)) char * strrchr_foo (const char *__s, int __c)  {
   return __builtin_strrchr (__s, __c);
 }
+
+extern inline void __attribute__((always_inline, __gnu_inline__))
+prefetch(void) {
+  __builtin_prefetch(0, 0, 1);
+}
+
 void f(void) {
   foo();
-  bar();
+  abs(0);
   strrchr_foo("", '.');
+  prefetch();
 }
 
 // CHECK-LABEL: define void @f()
 // CHECK: call void @foo()
-// CHECK-NEXT: call void @bar()
-// CHECK-NEXT: call i8* @strrchr(
-// CHECK-NEXT: ret void
+// CHECK: call i32 @abs(i32 0)
+// CHECK: call i8* @strrchr(
+// CHECK: call void @llvm.prefetch(
+// CHECK: ret void
 
 // CHECK: declare void @foo()
-// CHECK: declare void @bar()
+// CHECK: declare i32 @abs(i32
 // CHECK: declare i8* @strrchr(i8*, i32)
+// CHECK: declare void @llvm.prefetch(





More information about the cfe-commits mailing list