Skip to content

Commit 3287ae8

Browse files
authored
[clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' (#73290)
Co-authored-by: huqizhi <[email protected]>
1 parent 1debbae commit 3287ae8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

clang/include/clang/Basic/AttributeCommonInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ class AttributeCommonInfo {
177177
IsRegularKeywordAttribute);
178178
}
179179
const IdentifierInfo *getAttrName() const { return AttrName; }
180+
void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; }
180181
SourceLocation getLoc() const { return AttrRange.getBegin(); }
181182
SourceRange getRange() const { return AttrRange; }
182183
void setRange(SourceRange R) { AttrRange = R; }

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9073,6 +9073,7 @@ class AttrImporter {
90739073

90749074
ToAttr = FromAttr->clone(Importer.getToContext());
90759075
ToAttr->setRange(ToRange);
9076+
ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
90769077
}
90779078

90789079
// Get the result of the previous import attempt (can be used only once).

clang/unittests/AST/ASTImporterTest.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "clang/AST/RecordLayout.h"
1414
#include "clang/ASTMatchers/ASTMatchers.h"
15+
#include "clang/Testing/CommandLineArgs.h"
1516
#include "llvm/Support/SmallVectorMemoryBuffer.h"
1617

1718
#include "clang/AST/DeclContextInternals.h"
@@ -7379,11 +7380,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase {
73797380
}
73807381

73817382
template <class DT, class AT>
7382-
void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) {
7383+
void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr,
7384+
TestLanguage Lang = Lang_CXX11) {
73837385
static_assert(std::is_base_of<Attr, AT>::value, "AT should be an Attr");
73847386
static_assert(std::is_base_of<Decl, DT>::value, "DT should be a Decl");
73857387

7386-
Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
7388+
Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
73877389
DT *FromD =
73887390
FirstDeclMatcher<DT>().match(FromTU, namedDecl(hasName("test")));
73897391
ASSERT_TRUE(FromD);
@@ -7669,6 +7671,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
76697671
checkImportVariadicArg(FromAttr->args(), ToAttr->args());
76707672
}
76717673

7674+
TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
7675+
NoThrowAttr *FromAttr, *ToAttr;
7676+
importAttr<FunctionDecl>("void test () __attribute__ ((__nothrow__));",
7677+
FromAttr, ToAttr, Lang_C99);
7678+
checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
7679+
}
7680+
76727681
template <typename T>
76737682
auto ExtendWithOptions(const T &Values, const std::vector<std::string> &Args) {
76747683
auto Copy = Values;

0 commit comments

Comments
 (0)