Skip to content

Commit 20aab60

Browse files
author
huqizhi
committed
[clang][ASTImporter] IdentifierInfo of Attribute should be set using ToASTContext
1 parent c072247 commit 20aab60

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
@@ -9063,6 +9063,7 @@ class AttrImporter {
90639063

90649064
ToAttr = FromAttr->clone(Importer.getToContext());
90659065
ToAttr->setRange(ToRange);
9066+
ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
90669067
}
90679068

90689069
// 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"
@@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase {
73627363
}
73637364

73647365
template <class DT, class AT>
7365-
void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) {
7366+
void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr,
7367+
TestLanguage Lang = Lang_CXX11) {
73667368
static_assert(std::is_base_of<Attr, AT>::value, "AT should be an Attr");
73677369
static_assert(std::is_base_of<Decl, DT>::value, "DT should be a Decl");
73687370

7369-
Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
7371+
Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
73707372
DT *FromD =
73717373
FirstDeclMatcher<DT>().match(FromTU, namedDecl(hasName("test")));
73727374
ASSERT_TRUE(FromD);
@@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
76527654
checkImportVariadicArg(FromAttr->args(), ToAttr->args());
76537655
}
76547656

7657+
TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
7658+
NoThrowAttr *FromAttr, *ToAttr;
7659+
importAttr<FunctionDecl>("void test () __attribute__ ((__nothrow__));",
7660+
FromAttr, ToAttr, Lang_C99);
7661+
checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
7662+
}
7663+
76557664
template <typename T>
76567665
auto ExtendWithOptions(const T &Values, const std::vector<std::string> &Args) {
76577666
auto Copy = Values;

0 commit comments

Comments
 (0)