]> granicus.if.org Git - clang/commitdiff
<rdar://problem/13560075> Teach name lookup for builtin names to find hidden declarat...
authorDouglas Gregor <dgregor@apple.com>
Wed, 3 Apr 2013 23:06:26 +0000 (23:06 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 3 Apr 2013 23:06:26 +0000 (23:06 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178711 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLookup.cpp
test/Modules/Inputs/builtin.h [new file with mode: 0644]
test/Modules/Inputs/builtin_sub.h [new file with mode: 0644]
test/Modules/Inputs/module.map
test/Modules/builtins.m [new file with mode: 0644]

index 2b3ca3f0ef786085cf0c0367df5095317cadf8de..f26b8ed7f7ae8c30861a96861328fd14dbfb20d6 100644 (file)
@@ -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/test/Modules/Inputs/builtin.h b/test/Modules/Inputs/builtin.h
new file mode 100644 (file)
index 0000000..7be9017
--- /dev/null
@@ -0,0 +1,3 @@
+int i;
+int *p = &i;
+
diff --git a/test/Modules/Inputs/builtin_sub.h b/test/Modules/Inputs/builtin_sub.h
new file mode 100644 (file)
index 0000000..79e3c03
--- /dev/null
@@ -0,0 +1,4 @@
+int getBos1(void) {
+  return __builtin_object_size(p, 0);
+}
+
index 93ba4935ffd2a00054c0a75aafd11642d41ed521..595e5d88468a96d71837e5402af17e4f0a7777e2 100644 (file)
@@ -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/test/Modules/builtins.m b/test/Modules/builtins.m
new file mode 100644 (file)
index 0000000..40b4f9c
--- /dev/null
@@ -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