summaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2023-04-05 16:41:30 +0100
committerRichard Sandiford <richard.sandiford@arm.com>2023-04-13 10:14:48 +0100
commite841d50926347c3596009dd4fbc4cbd1a1a2e0b8 (patch)
treece9d39b41dcc285c3b393a1d57e3ec3919e02c38 /clang/unittests
parentcafefe01604c12db7f860a29419b5940e0c993ae (diff)
downloadllvm-e841d50926347c3596009dd4fbc4cbd1a1a2e0b8.tar.gz
[clang] Ensure that Attr::Create(Implicit) chooses a valid syntax
The purpose of this patch and follow-on patches is to ensure that AttributeCommonInfos always have a syntax that is appropriate for their kind (i.e. that it matches one of the entries in Attr.td). The attribute-specific Create and CreateImplicit methods had four overloads, based on their tail arguments: (1) no extra arguments (2) an AttributeCommonInfo (3) a SourceRange (4) a SourceRange, a syntax, and (where necessary) a spelling When (4) had a spelling argument, it defaulted to SpellingNotCalculated. One disadvantage of this was that (1) and (3) zero-initialized the syntax field of the AttributeCommonInfo, which corresponds to AS_GNU. But AS_GNU isn't always listed as a possibility in Attr.td. This patch therefore removes (1) and (3) and instead provides the same functionality using default arguments on (4) (a bit like the existing default argument for the spelling). The default syntax is taken from the attribute's first valid spelling. Doing that raises the question: what should happen for attributes like AlignNatural and CUDAInvalidTarget that are only ever created implicitly, and so have no source-code manifestation at all? The patch adds a new AS_Implicit "syntax" for that case. The patch also removes the syntax argument for these attributes, since the syntax must always be AS_Implicit. For similar reasons, the patch removes the syntax argument if there is exactly one valid spelling. Doing this means that AttributeCommonInfo no longer needs the single-argument constructors. It is always given a syntax instead. Differential Revision: https://reviews.llvm.org/D148101
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/AST/DeclTest.cpp8
1 files changed, 2 insertions, 6 deletions
diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index ad89596328ed..0cc7f93153f4 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -88,12 +88,8 @@ TEST(Decl, AsmLabelAttr) {
NamedDecl *DeclG = *(++DeclS->method_begin());
// Attach asm labels to the decls: one literal, and one not.
- DeclF->addAttr(::new (Ctx) AsmLabelAttr(
- Ctx, AttributeCommonInfo{SourceLocation()}, "foo",
- /*LiteralLabel=*/true));
- DeclG->addAttr(::new (Ctx) AsmLabelAttr(
- Ctx, AttributeCommonInfo{SourceLocation()}, "goo",
- /*LiteralLabel=*/false));
+ DeclF->addAttr(AsmLabelAttr::Create(Ctx, "foo", /*LiteralLabel=*/true));
+ DeclG->addAttr(AsmLabelAttr::Create(Ctx, "goo", /*LiteralLabel=*/false));
// Mangle the decl names.
std::string MangleF, MangleG;