r178711 - <rdar://problem/13560075> Teach name lookup for builtin names to find hidden declarations.
Douglas Gregor
dgregor at apple.com
Wed Apr 3 16:06:26 PDT 2013
Author: dgregor
Date: Wed Apr 3 18:06:26 2013
New Revision: 178711
URL: http://llvm.org/viewvc/llvm-project?rev=178711&view=rev
Log:
<rdar://problem/13560075> Teach name lookup for builtin names to find hidden declarations.
Normal name lookup ignores any hidden declarations. When name lookup
for builtin declarations fails, we just synthesize a new
declaration at the point of use. With modules, this could lead to
multiple declarations of the same builtin, if one came from a (hidden)
submodule that was later made visible. Teach name lookup to always
find builtin names, so we don't create these redundant declarations in
the first place.
Added:
cfe/trunk/test/Modules/Inputs/builtin.h
cfe/trunk/test/Modules/Inputs/builtin_sub.h
cfe/trunk/test/Modules/builtins.m
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/Modules/Inputs/module.map
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=178711&r1=178710&r2=178711&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Apr 3 18:06:26 2013
@@ -287,10 +287,10 @@ void LookupResult::configure() {
IDNS = getIDNS(LookupKind, SemaRef.getLangOpts().CPlusPlus,
isForRedeclaration());
- // If we're looking for one of the allocation or deallocation
- // operators, make sure that the implicitly-declared new and delete
- // operators can be found.
if (!isForRedeclaration()) {
+ // If we're looking for one of the allocation or deallocation
+ // operators, make sure that the implicitly-declared new and delete
+ // operators can be found.
switch (NameInfo.getName().getCXXOverloadedOperator()) {
case OO_New:
case OO_Delete:
@@ -302,6 +302,15 @@ void LookupResult::configure() {
default:
break;
}
+
+ // Compiler builtins are always visible, regardless of where they end
+ // up being declared.
+ if (IdentifierInfo *Id = NameInfo.getName().getAsIdentifierInfo()) {
+ if (unsigned BuiltinID = Id->getBuiltinID()) {
+ if (!SemaRef.Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))
+ AllowHidden = true;
+ }
+ }
}
}
Added: cfe/trunk/test/Modules/Inputs/builtin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/builtin.h?rev=178711&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/builtin.h (added)
+++ cfe/trunk/test/Modules/Inputs/builtin.h Wed Apr 3 18:06:26 2013
@@ -0,0 +1,3 @@
+int i;
+int *p = &i;
+
Added: cfe/trunk/test/Modules/Inputs/builtin_sub.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/builtin_sub.h?rev=178711&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/builtin_sub.h (added)
+++ cfe/trunk/test/Modules/Inputs/builtin_sub.h Wed Apr 3 18:06:26 2013
@@ -0,0 +1,4 @@
+int getBos1(void) {
+ return __builtin_object_size(p, 0);
+}
+
Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=178711&r1=178710&r2=178711&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Wed Apr 3 18:06:26 2013
@@ -192,3 +192,10 @@ module config {
module diag_pragma {
header "diag_pragma.h"
}
+
+module builtin {
+ header "builtin.h"
+ explicit module sub {
+ header "builtin_sub.h"
+ }
+}
Added: cfe/trunk/test/Modules/builtins.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/builtins.m?rev=178711&view=auto
==============================================================================
--- cfe/trunk/test/Modules/builtins.m (added)
+++ cfe/trunk/test/Modules/builtins.m Wed Apr 3 18:06:26 2013
@@ -0,0 +1,16 @@
+ at import builtin;
+
+int foo() {
+ return __builtin_object_size(p, 0);
+}
+
+ at import builtin.sub;
+
+int bar() {
+ return __builtin_object_size(p, 0);
+}
+
+
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -I %S/Inputs %s -verify
+// expected-no-diagnostics
More information about the cfe-commits
mailing list