summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-04-03 23:06:26 +0000
committerDouglas Gregor <dgregor@apple.com>2013-04-03 23:06:26 +0000
commit151976694a8e63bb6ff5e280d77371a9490b9413 (patch)
treec6cba7c16dcc09bedff10266bba0c3f186ccae1f
parent54dc7fdefb05ce04e7864335e231c4f597967b6d (diff)
downloadbcm5719-llvm-151976694a8e63bb6ff5e280d77371a9490b9413.tar.gz
bcm5719-llvm-151976694a8e63bb6ff5e280d77371a9490b9413.zip
<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. llvm-svn: 178711
-rw-r--r--clang/lib/Sema/SemaLookup.cpp15
-rw-r--r--clang/test/Modules/Inputs/builtin.h3
-rw-r--r--clang/test/Modules/Inputs/builtin_sub.h4
-rw-r--r--clang/test/Modules/Inputs/module.map7
-rw-r--r--clang/test/Modules/builtins.m16
5 files changed, 42 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 2b3ca3f0ef7..f26b8ed7f7a 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -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;
+ }
+ }
}
}
diff --git a/clang/test/Modules/Inputs/builtin.h b/clang/test/Modules/Inputs/builtin.h
new file mode 100644
index 00000000000..7be90177d19
--- /dev/null
+++ b/clang/test/Modules/Inputs/builtin.h
@@ -0,0 +1,3 @@
+int i;
+int *p = &i;
+
diff --git a/clang/test/Modules/Inputs/builtin_sub.h b/clang/test/Modules/Inputs/builtin_sub.h
new file mode 100644
index 00000000000..79e3c033259
--- /dev/null
+++ b/clang/test/Modules/Inputs/builtin_sub.h
@@ -0,0 +1,4 @@
+int getBos1(void) {
+ return __builtin_object_size(p, 0);
+}
+
diff --git a/clang/test/Modules/Inputs/module.map b/clang/test/Modules/Inputs/module.map
index 93ba4935ffd..595e5d88468 100644
--- a/clang/test/Modules/Inputs/module.map
+++ b/clang/test/Modules/Inputs/module.map
@@ -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"
+ }
+}
diff --git a/clang/test/Modules/builtins.m b/clang/test/Modules/builtins.m
new file mode 100644
index 00000000000..40b4f9c7439
--- /dev/null
+++ b/clang/test/Modules/builtins.m
@@ -0,0 +1,16 @@
+@import builtin;
+
+int foo() {
+ return __builtin_object_size(p, 0);
+}
+
+@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
OpenPOWER on IntegriCloud