From: Chandler Carruth Date: Wed, 22 Mar 2017 10:38:07 +0000 (+0000) Subject: Remove an overly aggressive assert in r298491 and leave a comment X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f59e14431c4b7dbea2c39db286f5a309c48f5b24;p=clang Remove an overly aggressive assert in r298491 and leave a comment explaining why we have to ignore errors here even though in other parts of codegen we can be more strict with builtins. Also add a test case based on the code in a TSan test that found this issue. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@298494 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index b9090b413c..e56fe2c1c1 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -1813,7 +1813,11 @@ void CodeGenModule::ConstructAttributeList( ASTContext::GetBuiltinTypeError Error; getContext().GetBuiltinType(BuiltinID, Error, nullptr, &OverrideNonnullReturn, &OverrideNonnullArgs); - assert(Error == ASTContext::GE_None && "Should not codegen an error"); + // Note that we can't check the 'Error' here as there may be errors that + // have been diagnosed and reported to the programmer as warnings but + // repaired in the AST such as for implicit declarations of builtin + // functions. None of those impact our usage of this to analyze attributes + // for the builtins. } bool HasOptnone = false; diff --git a/test/CodeGen/function-attributes.c b/test/CodeGen/function-attributes.c index 2139f6fe65..49f47bf74d 100644 --- a/test/CodeGen/function-attributes.c +++ b/test/CodeGen/function-attributes.c @@ -108,6 +108,20 @@ void f20(void) { _setjmp(0); } +// Bogus declarations that will end up with bad types when detecting builtins, +// but that we will still process when considering whether to add attributes. +struct __jmp_buf_tag; +extern int __sigsetjmp(struct __jmp_buf_tag *__env, int __savemask); + +// CHECK-LABEL: define void @f21() +// CHECK: { +// CHECK: call i32 @__sigsetjmp(%{{.*}}* null, i32 0) +// CHECK: [[RT_CALL]] +// CHECK: ret void +void f21(void) { + __sigsetjmp(0, 0); +} + // CHECK: attributes [[NUW]] = { nounwind optsize{{.*}} } // CHECK: attributes [[AI]] = { alwaysinline nounwind optsize{{.*}} } // CHECK: attributes [[NUW_OS_RN]] = { nounwind optsize readnone{{.*}} }