diff options
author | Ben Langmuir <blangmuir@apple.com> | 2016-02-03 03:26:19 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2016-02-03 03:26:19 +0000 |
commit | 6a34e10514ab154e364f105ca5980acd479bf925 (patch) | |
tree | 7a86c182e42ce3dcd47adb81c43696f58d79adb2 | |
parent | 83cc981c49447c96bd311b5414535338c4d15bcf (diff) | |
download | bcm5719-llvm-6a34e10514ab154e364f105ca5980acd479bf925.tar.gz bcm5719-llvm-6a34e10514ab154e364f105ca5980acd479bf925.zip |
Make CF constant string decl visible to name lookup to fix module errors
The return type of the __builtin___*StringMakeConstantString functions
is a pointer to a struct, so we need that struct to be visible to name
lookup so that we will correctly merge multiple declarations of that
type if they come from different modules.
Incidentally, to make this visible to name lookup we need to rename the
type to __NSConstantString, since the real NSConstantString is an
Objective-C interface type. This shouldn't affect anyone outside the
compiler since users of the constant string builtins cast the result
immediately to CFStringRef.
Since this struct type is otherwise implicitly created by the AST
context and cannot access namelookup, we make this a predefined type
and initialize it in Sema.
Note: this issue of builtins that refer to types not visible to name
lookup technically also affects other builtins (e.g. objc_msgSendSuper),
but in all other cases the builtin is a library builtin and the issue
goes away if you include the library that defines the types it uses,
unlike for these constant string builtins.
rdar://problem/24425801
llvm-svn: 259624
-rw-r--r-- | clang/include/clang/AST/ASTContext.h | 1 | ||||
-rw-r--r-- | clang/include/clang/Serialization/ASTBitCodes.h | 5 | ||||
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 2 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/2010-02-01-utf16-with-null.m | 4 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/arc-no-arc-exceptions.m | 2 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/tentative-cfconstantstring.m | 4 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/builtin.h | 7 | ||||
-rw-r--r-- | clang/test/Modules/builtins.m | 26 |
11 files changed, 54 insertions, 18 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index abf92948bb4..1d053411ebc 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1385,6 +1385,7 @@ public: return QualType(); } void setCFConstantStringType(QualType T); + TagDecl *getCFConstantStringDecl() const; // This setter/getter represents the ObjC type for an NSConstantString. void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl); diff --git a/clang/include/clang/Serialization/ASTBitCodes.h b/clang/include/clang/Serialization/ASTBitCodes.h index bd784c7c5c0..9e835d6d9f7 100644 --- a/clang/include/clang/Serialization/ASTBitCodes.h +++ b/clang/include/clang/Serialization/ASTBitCodes.h @@ -987,13 +987,16 @@ namespace clang { /// \brief The internal '__make_integer_seq' template. PREDEF_DECL_MAKE_INTEGER_SEQ_ID = 13, + + /// \brief The internal '__NSConstantString' type. + PREDEF_DECL_CF_CONSTANT_STRING_ID = 14, }; /// \brief The number of declaration IDs that are predefined. /// /// For more information about predefined declarations, see the /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants. - const unsigned int NUM_PREDEF_DECL_IDS = 14; + const unsigned int NUM_PREDEF_DECL_IDS = 15; /// \brief Record code for a list of local redeclarations of a declaration. const unsigned int LOCAL_REDECLARATIONS = 50; diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 02b3e51d1de..fc5ff8668e9 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -4868,10 +4868,11 @@ int ASTContext::getIntegerTypeOrder(QualType LHS, QualType RHS) const { return 1; } -// getCFConstantStringType - Return the type used for constant CFStrings. -QualType ASTContext::getCFConstantStringType() const { +TagDecl *ASTContext::getCFConstantStringDecl() const { if (!CFConstantStringTypeDecl) { - CFConstantStringTypeDecl = buildImplicitRecord("NSConstantString"); + // This type is designed to be compatible with NSConstantString, but cannot + // use the same name, since NSConstantString is an interface. + CFConstantStringTypeDecl = buildImplicitRecord("__NSConstantString"); CFConstantStringTypeDecl->startDefinition(); QualType FieldTypes[4]; @@ -4901,7 +4902,12 @@ QualType ASTContext::getCFConstantStringType() const { CFConstantStringTypeDecl->completeDefinition(); } - return getTagDeclType(CFConstantStringTypeDecl); + return CFConstantStringTypeDecl; +} + +// getCFConstantStringType - Return the type used for constant CFStrings. +QualType ASTContext::getCFConstantStringType() const { + return getTagDeclType(getCFConstantStringDecl()); } QualType ASTContext::getObjCSuperType() const { diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 39b8cc9f0c6..3745cdd9a59 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -189,6 +189,10 @@ void Sema::Initialize() { DeclarationName Protocol = &Context.Idents.get("Protocol"); if (IdResolver.begin(Protocol) == IdResolver.end()) PushOnScopeChains(Context.getObjCProtocolDecl(), TUScope); + + DeclarationName ConstantString = &Context.Idents.get("NSConstantString"); + if (IdResolver.begin(ConstantString) == IdResolver.end()) + PushOnScopeChains(Context.getCFConstantStringDecl(), TUScope); } // Initialize Microsoft "predefined C++ types". diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 72fbea6e9a8..1fbff107ea5 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -6444,6 +6444,9 @@ static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: return Context.getMakeIntegerSeqDecl(); + + case PREDEF_DECL_CF_CONSTANT_STRING_ID: + return Context.getCFConstantStringDecl(); } llvm_unreachable("PredefinedDeclIDs unknown enum value"); } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index ec04cd6c1fa..a590e188eca 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -4152,6 +4152,8 @@ uint64_t ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, RegisterPredefDecl(Context.ExternCContext, PREDEF_DECL_EXTERN_C_CONTEXT_ID); RegisterPredefDecl(Context.MakeIntegerSeqDecl, PREDEF_DECL_MAKE_INTEGER_SEQ_ID); + RegisterPredefDecl(Context.CFConstantStringTypeDecl, + PREDEF_DECL_CF_CONSTANT_STRING_ID); // Build a record containing all of the tentative definitions in this file, in // TentativeDefinitions order. Generally, this record will be empty for diff --git a/clang/test/CodeGenObjC/2010-02-01-utf16-with-null.m b/clang/test/CodeGenObjC/2010-02-01-utf16-with-null.m index 46ce3b289fc..856ac9ac97b 100644 --- a/clang/test/CodeGenObjC/2010-02-01-utf16-with-null.m +++ b/clang/test/CodeGenObjC/2010-02-01-utf16-with-null.m @@ -2,6 +2,6 @@ // rdar://7589850 // CHECK: @.str = private unnamed_addr constant [9 x i16] [i16 103, i16 111, i16 111, i16 100, i16 0, i16 98, i16 121, i16 101, i16 0], section "__TEXT,__ustring", align 2 -// CHECK: @_unnamed_cfstring_ = private constant %struct.NSConstantString { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 2000, i8* bitcast ([9 x i16]* @.str to i8*), i32 8 }, section "__DATA,__cfstring" -// CHECK: @P = global i8* bitcast (%struct.NSConstantString* @_unnamed_cfstring_ to i8*), align 4 +// CHECK: @_unnamed_cfstring_ = private constant %struct.__NSConstantString { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 2000, i8* bitcast ([9 x i16]* @.str to i8*), i32 8 }, section "__DATA,__cfstring" +// CHECK: @P = global i8* bitcast (%struct.__NSConstantString* @_unnamed_cfstring_ to i8*), align 4 void *P = @"good\0bye"; diff --git a/clang/test/CodeGenObjC/arc-no-arc-exceptions.m b/clang/test/CodeGenObjC/arc-no-arc-exceptions.m index 82977b0a175..30424e7fb36 100644 --- a/clang/test/CodeGenObjC/arc-no-arc-exceptions.m +++ b/clang/test/CodeGenObjC/arc-no-arc-exceptions.m @@ -34,7 +34,7 @@ void test1(id x) { void NSLog(id, ...); // CHECK-LABEL: define void @test2( -// CHECK: invoke void (i8*, ...) @NSLog(i8* bitcast (%struct.NSConstantString* @_unnamed_cfstring_ to i8*), i32* %{{.*}}) +// CHECK: invoke void (i8*, ...) @NSLog(i8* bitcast (%struct.__NSConstantString* @_unnamed_cfstring_ to i8*), i32* %{{.*}}) // CHECK: to label %{{.*}} unwind label %{{.*}}, !clang.arc.no_objc_arc_exceptions ! // NO-METADATA-LABEL: define void @test2( // NO-METADATA-NOT: !clang.arc.no_objc_arc_exceptions diff --git a/clang/test/CodeGenObjC/tentative-cfconstantstring.m b/clang/test/CodeGenObjC/tentative-cfconstantstring.m index 5b3c3bd9249..0c692c37c95 100644 --- a/clang/test/CodeGenObjC/tentative-cfconstantstring.m +++ b/clang/test/CodeGenObjC/tentative-cfconstantstring.m @@ -32,12 +32,12 @@ static inline void _inlineFunction() { @end // CHECK: @__CFConstantStringClassReference = common global [24 x i32] zeroinitializer, align 16 -// CHECK: @_unnamed_cfstring_{{.*}} = private constant %struct.NSConstantString { i32* getelementptr inbounds ([24 x i32], [24 x i32]* @__CFConstantStringClassReference, i32 0, i32 0) +// CHECK: @_unnamed_cfstring_{{.*}} = private constant %struct.__NSConstantString { i32* getelementptr inbounds ([24 x i32], [24 x i32]* @__CFConstantStringClassReference, i32 0, i32 0) // CHECK-LABEL: define internal void @_inlineFunction() // CHECK: [[ZERO:%.*]] = load %struct._class_t*, %struct._class_t** @"OBJC_CLASSLIST_REFERENCES_ // CHECK-NEXT: [[ONE:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_ // CHECK-NEXT: [[TWO:%.*]] = bitcast %struct._class_t* [[ZERO]] to i8* -// CHECK-NEXT: call void (i8*, i8*, [[T:%.*]]*, ...) bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, [[T:%.*]]*, ...)*)(i8* [[TWO]], i8* [[ONE]], [[T:%.*]]* bitcast (%struct.NSConstantString* @_unnamed_cfstring_{{.*}} to [[T:%.*]]*)) +// CHECK-NEXT: call void (i8*, i8*, [[T:%.*]]*, ...) bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, [[T:%.*]]*, ...)*)(i8* [[TWO]], i8* [[ONE]], [[T:%.*]]* bitcast (%struct.__NSConstantString* @_unnamed_cfstring_{{.*}} to [[T:%.*]]*)) // CHECK-NEXT: ret void diff --git a/clang/test/Modules/Inputs/builtin.h b/clang/test/Modules/Inputs/builtin.h index 7be90177d19..d8779452342 100644 --- a/clang/test/Modules/Inputs/builtin.h +++ b/clang/test/Modules/Inputs/builtin.h @@ -1,3 +1,10 @@ int i; int *p = &i; +#ifdef __OBJC__ +void use_constant_string_builtins(void) { + (void)__builtin___CFStringMakeConstantString(""); + (void)__builtin___NSStringMakeConstantString(""); +} +#endif + diff --git a/clang/test/Modules/builtins.m b/clang/test/Modules/builtins.m index 33d23979ce7..a835039cc60 100644 --- a/clang/test/Modules/builtins.m +++ b/clang/test/Modules/builtins.m @@ -1,3 +1,17 @@ +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs %s -verify + +// RUN: rm -rf %t.pch.cache +// RUN: %clang_cc1 -fmodules-cache-path=%t.pch.cache -fmodules -fimplicit-module-maps -I %S/Inputs -emit-pch -o %t.pch -x objective-c-header %S/Inputs/use-builtin.h +// RUN: %clang_cc1 -fmodules-cache-path=%t.pch.cache -fmodules -fimplicit-module-maps -I %S/Inputs %s -include-pch %t.pch %s -verify + +// expected-no-diagnostics + +void use_constant_string_builtins1(void) { + (void)__builtin___CFStringMakeConstantString(""); + (void)__builtin___NSStringMakeConstantString(""); +} + @import builtin; int foo() { @@ -14,11 +28,7 @@ int baz() { return IS_CONST(0); } -// RUN: rm -rf %t -// RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -I %S/Inputs %s -verify - -// RUN: rm -rf %t.pch.cache -// RUN: %clang_cc1 -fmodules-cache-path=%t.pch.cache -fmodules -fimplicit-module-maps -I %S/Inputs -emit-pch -o %t.pch -x objective-c-header %S/Inputs/use-builtin.h -// RUN: %clang_cc1 -fmodules-cache-path=%t.pch.cache -fmodules -fimplicit-module-maps -I %S/Inputs %s -include-pch %t.pch %s -verify - -// expected-no-diagnostics +void use_constant_string_builtins2(void) { + (void)__builtin___CFStringMakeConstantString(""); + (void)__builtin___NSStringMakeConstantString(""); +} |