Skip to content

[clang][ASTImporter] IdentifierInfo of Attribute should be set using 'ToASTContext' #73290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Basic/AttributeCommonInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class AttributeCommonInfo {
IsRegularKeywordAttribute);
}
const IdentifierInfo *getAttrName() const { return AttrName; }
void setAttrName(const IdentifierInfo *AttrNameII) { AttrName = AttrNameII; }
SourceLocation getLoc() const { return AttrRange.getBegin(); }
SourceRange getRange() const { return AttrRange; }
void setRange(SourceRange R) { AttrRange = R; }
Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9063,6 +9063,7 @@ class AttrImporter {

ToAttr = FromAttr->clone(Importer.getToContext());
ToAttr->setRange(ToRange);
ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
}

// Get the result of the previous import attempt (can be used only once).
Expand Down
13 changes: 11 additions & 2 deletions clang/unittests/AST/ASTImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "clang/AST/RecordLayout.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Testing/CommandLineArgs.h"
#include "llvm/Support/SmallVectorMemoryBuffer.h"

#include "clang/AST/DeclContextInternals.h"
Expand Down Expand Up @@ -7362,11 +7363,12 @@ struct ImportAttributes : public ASTImporterOptionSpecificTestBase {
}

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

Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
Decl *FromTU = getTuDecl(Code, Lang, "input.cc");
DT *FromD =
FirstDeclMatcher<DT>().match(FromTU, namedDecl(hasName("test")));
ASSERT_TRUE(FromD);
Expand Down Expand Up @@ -7652,6 +7654,13 @@ TEST_P(ImportAttributes, ImportLocksExcluded) {
checkImportVariadicArg(FromAttr->args(), ToAttr->args());
}

TEST_P(ImportAttributes, ImportC99NoThrowAttr) {
NoThrowAttr *FromAttr, *ToAttr;
importAttr<FunctionDecl>("void test () __attribute__ ((__nothrow__));",
FromAttr, ToAttr, Lang_C99);
checkImported(FromAttr->getAttrName(), ToAttr->getAttrName());
}

template <typename T>
auto ExtendWithOptions(const T &Values, const std::vector<std::string> &Args) {
auto Copy = Values;
Expand Down