diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-21 19:47:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-21 19:47:46 +0000 |
commit | 9246b6830a468d9d0a0925eae168543b8d603e29 (patch) | |
tree | 3e36c7cd14cc4b3d92eab92de9f75fbaa22a4b3c /clang/lib | |
parent | fd4da713435a470be221ae1b823b3cb8ef518a60 (diff) | |
download | bcm5719-llvm-9246b6830a468d9d0a0925eae168543b8d603e29.tar.gz bcm5719-llvm-9246b6830a468d9d0a0925eae168543b8d603e29.zip |
In C++, if the user redeclares a builtin function with a type that is
inconsistent with the type that the builtin *should* have, forget
about the builtin altogether: we don't want subsequence analyses,
CodeGen, etc., to think that we have a proper builtin function.
C is protected from errors here because it allows one to use a
library builtin without having a declaration, and detects inconsistent
(re-)declarations of builtins during declaration merging. C++ was
unprotected, and therefore would crash.
Fixes PR8839.
llvm-svn: 122351
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/Builtins.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 12 |
2 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index 3eacb3aa611..9ecb0c0c8b7 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -80,6 +80,10 @@ Builtin::Context::GetBuiltinNames(llvm::SmallVectorImpl<const char *> &Names, Names.push_back(TSRecords[i].Name); } +void Builtin::Context::ForgetBuiltin(unsigned ID, IdentifierTable &Table) { + Table.get(GetRecord(ID).Name).setBuiltinID(0); +} + bool Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg) { diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ad0c077aad4..bc91eb04396 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -4285,6 +4285,18 @@ void Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD, // during delayed parsing anyway. if (!CurContext->isRecord()) CheckCXXDefaultArguments(NewFD); + + // If this function declares a builtin function, check the type of this + // declaration against the expected type for the builtin. + if (unsigned BuiltinID = NewFD->getBuiltinID()) { + ASTContext::GetBuiltinTypeError Error; + QualType T = Context.GetBuiltinType(BuiltinID, Error); + if (!T.isNull() && !Context.hasSameType(T, NewFD->getType())) { + // The type of this function differs from the type of the builtin, + // so forget about the builtin entirely. + Context.BuiltinInfo.ForgetBuiltin(BuiltinID, Context.Idents); + } + } } } |