Don't forget about a builtin if we're about to redeclare it and we couldn't

create an implicit declaration of it (because some type it depends on is
unavailable). This had the effect of causing us to not implicitly give it the
right attributes. It turns out that glibc's __sigsetjmp is declared before
sigjmp_buf is declared, and this resulted in us not implicitly giving it
__attribute__((returns_twice)), which in turn resulted in miscompiles in any C
code calling glibc's sigsetjmp.

(See also the vaguely-related sourceware.org/PR4662.)

llvm-svn: 199850
This commit is contained in:
Richard Smith 2014-01-22 23:07:19 +00:00
parent a5adf489b7
commit 8c7bd6ac1a
2 changed files with 9 additions and 8 deletions

View File

@ -545,14 +545,6 @@ static bool LookupBuiltin(Sema &S, LookupResult &R) {
R.addDecl(D);
return true;
}
if (R.isForRedeclaration()) {
// If we're redeclaring this function anyway, forget that
// this was a builtin at all.
S.Context.BuiltinInfo.ForgetBuiltin(BuiltinID, S.Context.Idents);
}
return false;
}
}
}

View File

@ -1,4 +1,6 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: not %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
void f() {
int *ptr = malloc(sizeof(int) * 10); // expected-warning{{implicitly declaring library function 'malloc' with type}} \
// expected-note{{please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'}} \
@ -57,3 +59,10 @@ void snprintf() { }
void longjmp(); // expected-warning{{declaration of built-in function 'longjmp' requires inclusion of the header <setjmp.h>}}
extern float fmaxf(float, float);
struct __jmp_buf_tag {};
void sigsetjmp(struct __jmp_buf_tag[1], int); // expected-warning{{declaration of built-in function 'sigsetjmp' requires inclusion of the header <setjmp.h>}}
// CHECK: FunctionDecl {{.*}} <line:[[@LINE-2]]:1, col:44> sigsetjmp '
// CHECK-NOT: FunctionDecl
// CHECK: ReturnsTwiceAttr {{.*}} <{{.*}}> Implicit