Change DIBuilder::createImportedDeclaration from taking a DIScope to a DIDescriptor.
authorFrederic Riss <friss@apple.com>
Thu, 6 Nov 2014 17:46:55 +0000 (17:46 +0000)
committerFrederic Riss <friss@apple.com>
Thu, 6 Nov 2014 17:46:55 +0000 (17:46 +0000)
Imported declarations can be DIGlobalVariables which aren't a DIScope. Today
clang (unknowingly I believe) shoehorns these into a DIScope and it all works
just because we never access the fields.

llvm-svn: 221466

llvm/include/llvm/IR/DIBuilder.h
llvm/lib/IR/DIBuilder.cpp

index 8484d04..78ab3dc 100644 (file)
@@ -651,7 +651,7 @@ namespace llvm {
     /// @param Decl The declaration (or definition) of a function, type, or
     ///             variable
     /// @param Line Line number
-    DIImportedEntity createImportedDeclaration(DIScope Context, DIScope Decl,
+    DIImportedEntity createImportedDeclaration(DIScope Context, DIDescriptor Decl,
                                                unsigned Line,
                                                StringRef Name = StringRef());
     DIImportedEntity createImportedDeclaration(DIScope Context,
index 3276fe6..fbd1959 100644 (file)
@@ -190,10 +190,13 @@ DIImportedEntity DIBuilder::createImportedModule(DIScope Context,
 }
 
 DIImportedEntity DIBuilder::createImportedDeclaration(DIScope Context,
-                                                      DIScope Decl,
+                                                      DIDescriptor Decl,
                                                       unsigned Line, StringRef Name) {
+  // Make sure to use the unique identifier based metadata reference for
+  // types that have one.
+  Value *V = Decl.isType() ? DIType(Decl).getRef() : Decl;
   return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration,
-                                Context, Decl.getRef(), Line, Name,
+                                Context, V, Line, Name,
                                 AllImportedModules);
 }