[cfe-commits] r122351 - in /cfe/trunk: include/clang/Basic/Builtins.h lib/Basic/Builtins.cpp lib/Sema/SemaDecl.cpp test/CodeGenCXX/builtins.cpp
Douglas Gregor
dgregor at apple.com
Tue Dec 21 11:47:46 PST 2010
Author: dgregor
Date: Tue Dec 21 13:47:46 2010
New Revision: 122351
URL: http://llvm.org/viewvc/llvm-project?rev=122351&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGenCXX/builtins.cpp
Modified:
cfe/trunk/include/clang/Basic/Builtins.h
cfe/trunk/lib/Basic/Builtins.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/include/clang/Basic/Builtins.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=122351&r1=122350&r2=122351&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.h (original)
+++ cfe/trunk/include/clang/Basic/Builtins.h Tue Dec 21 13:47:46 2010
@@ -117,6 +117,10 @@
return strchr(GetRecord(ID).Attributes, 'f') != 0;
}
+ /// \brief Completely forget that the given ID was ever considered a builtin,
+ /// e.g., because the user provided a conflicting signature.
+ void ForgetBuiltin(unsigned ID, IdentifierTable &Table);
+
/// \brief If this is a library function that comes from a specific
/// header, retrieve that header name.
const char *getHeaderName(unsigned ID) const {
Modified: cfe/trunk/lib/Basic/Builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=122351&r1=122350&r2=122351&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Builtins.cpp (original)
+++ cfe/trunk/lib/Basic/Builtins.cpp Tue Dec 21 13:47:46 2010
@@ -80,6 +80,10 @@
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) {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=122351&r1=122350&r2=122351&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 21 13:47:46 2010
@@ -4285,6 +4285,18 @@
// 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);
+ }
+ }
}
}
Added: cfe/trunk/test/CodeGenCXX/builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtins.cpp?rev=122351&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/builtins.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/builtins.cpp Tue Dec 21 13:47:46 2010
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// PR8839
+extern "C" char memmove();
+
+int main() {
+ // CHECK: call signext i8 @memmove()
+ return memmove();
+}
More information about the cfe-commits
mailing list