summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-06-30 04:41:18 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-06-30 04:41:18 +0000
commit64b0bdf88afd11b4693b1553c8f5e13c1cb581ed (patch)
tree7e67742d24372db0f623c68ade4330156c1e6ea4
parent41bb43252b18f9687990b2dd5c53c8270c785a62 (diff)
downloadbcm5719-llvm-64b0bdf88afd11b4693b1553c8f5e13c1cb581ed.tar.gz
bcm5719-llvm-64b0bdf88afd11b4693b1553c8f5e13c1cb581ed.zip
[CodeGen] Tweak isTriviallyRecursive further
isTriviallyRecursive is a hack used to bridge a gap between the expectations that source code assumes and the semantics that LLVM IR can provide. Specifically, asm labels on functions are treated as an explicit name for a GlobalObject in Clang but treated like an output-processing step in GCC. Tweak this hack a little further to emit calls to library functions instead of emitting an incorrect definition. The definition in question would have available_externally linkage (this is OK) but result in a call to itself which will either result in an infinite loop or stack overflow. This fixes PR23964. llvm-svn: 241043
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp7
-rw-r--r--clang/test/CodeGen/pr9614.c7
2 files changed, 8 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 461f694acb0..ea09ba8d4fb 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1457,12 +1457,7 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) {
Name = FD->getName();
}
- auto &BI = Context.BuiltinInfo;
- unsigned BuiltinID = Context.Idents.get(Name).getBuiltinID();
- if (!BuiltinID || !BI.isPredefinedLibFunction(BuiltinID))
- return false;
-
- FunctionIsDirectlyRecursive Walker(Name, BI);
+ FunctionIsDirectlyRecursive Walker(Name, Context.BuiltinInfo);
Walker.TraverseFunctionDecl(const_cast<FunctionDecl*>(FD));
return Walker.Result;
}
diff --git a/clang/test/CodeGen/pr9614.c b/clang/test/CodeGen/pr9614.c
index de21dbbb23f..63cb5af1868 100644
--- a/clang/test/CodeGen/pr9614.c
+++ b/clang/test/CodeGen/pr9614.c
@@ -18,11 +18,16 @@ prefetch(void) {
__builtin_prefetch(0, 0, 1);
}
+extern inline __attribute__((__always_inline__, __gnu_inline__)) void *memchr(void *__s, int __c, __SIZE_TYPE__ __n) {
+ return __builtin_memchr(__s, __c, __n);
+}
+
void f(void) {
foo();
abs(0);
strrchr_foo("", '.');
prefetch();
+ memchr("", '.', 0);
}
// CHECK-LABEL: define void @f()
@@ -30,9 +35,11 @@ void f(void) {
// CHECK: call i32 @abs(i32 0)
// CHECK: call i8* @strrchr(
// CHECK: call void @llvm.prefetch(
+// CHECK: call i8* @memchr(
// CHECK: ret void
// CHECK: declare void @foo()
// CHECK: declare i32 @abs(i32
// CHECK: declare i8* @strrchr(i8*, i32)
+// CHECK: declare i8* @memchr(
// CHECK: declare void @llvm.prefetch(
OpenPOWER on IntegriCloud