[clang] c1fb23c - [clang][ASTImporter] Fix import of VarDecl regarding thread local storage spec

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 18 05:07:16 PDT 2021


Author: Balazs Benics
Date: 2021-03-18T13:06:38+01:00
New Revision: c1fb23c1aadd22e736c4a1c36c146bbfbc48f959

URL: https://github.com/llvm/llvm-project/commit/c1fb23c1aadd22e736c4a1c36c146bbfbc48f959
DIFF: https://github.com/llvm/llvm-project/commit/c1fb23c1aadd22e736c4a1c36c146bbfbc48f959.diff

LOG: [clang][ASTImporter] Fix import of VarDecl regarding thread local storage spec

After the import, we did not copy the `TSCSpec`.
This commit resolves that.

Reviewed By: balazske

Differential Revision: https://reviews.llvm.org/D98707

Added: 
    

Modified: 
    clang/lib/AST/ASTImporter.cpp
    clang/unittests/AST/ASTImporterTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f4dfc54b36cb..d48e173eb3b3 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -4018,6 +4018,7 @@ ExpectedDecl ASTNodeImporter::VisitVarDecl(VarDecl *D) {
                               D->getStorageClass()))
     return ToVar;
 
+  ToVar->setTSCSpec(D->getTSCSpec());
   ToVar->setQualifierInfo(ToQualifierLoc);
   ToVar->setAccess(D->getAccess());
   ToVar->setLexicalDeclContext(LexicalDC);

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 39612d43799b..43464cc0c9ca 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -735,6 +735,12 @@ TEST_P(ImportDecl, ImportRecordDeclInFunc) {
                  has(declStmt(hasSingleDecl(varDecl(hasName("d")))))))));
 }
 
+TEST_P(ImportDecl, ImportedVarDeclPreservesThreadLocalStorage) {
+  MatchVerifier<Decl> Verifier;
+  testImport("thread_local int declToImport;", Lang_CXX11, "", Lang_CXX11,
+             Verifier, varDecl(hasThreadStorageDuration()));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ImportRecordTypeInFunc) {
   Decl *FromTU = getTuDecl("int declToImport() { "
                            "  struct data_t {int a;int b;};"


        


More information about the cfe-commits mailing list