rsandifo-arm created this revision.
rsandifo-arm added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
rsandifo-arm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Following a suggestion from Erich in https://reviews.llvm.org/D148101,
this patch bumps AS_GNU to 1 so that syntax 0 is invalid. It also
asserts that the syntax is in range.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148148
Files:
clang/include/clang/Basic/AttributeCommonInfo.h
Index: clang/include/clang/Basic/AttributeCommonInfo.h
===================================================================
--- clang/include/clang/Basic/AttributeCommonInfo.h
+++ clang/include/clang/Basic/AttributeCommonInfo.h
@@ -25,7 +25,7 @@
/// The style used to specify an attribute.
enum Syntax {
/// __attribute__((...))
- AS_GNU,
+ AS_GNU = 1,
/// [[...]]
AS_CXX11,
@@ -122,37 +122,32 @@
AttributeCommonInfo(const IdentifierInfo *AttrName,
const IdentifierInfo *ScopeName, SourceRange AttrRange,
- SourceLocation ScopeLoc, Form FormUsed)
+ SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
: AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange),
- ScopeLoc(ScopeLoc),
- AttrKind(getParsedKind(AttrName, ScopeName, FormUsed.getSyntax())),
+ ScopeLoc(ScopeLoc), AttrKind(AttrKind),
SyntaxUsed(FormUsed.getSyntax()),
SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ IsAlignas(FormUsed.isAlignas()) {
+ assert(SyntaxUsed >= AS_GNU && SyntaxUsed <= AS_Implicit &&
+ "Invalid syntax!");
+ }
AttributeCommonInfo(const IdentifierInfo *AttrName,
const IdentifierInfo *ScopeName, SourceRange AttrRange,
- SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
- : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange),
- ScopeLoc(ScopeLoc), AttrKind(AttrKind),
- SyntaxUsed(FormUsed.getSyntax()),
- SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ SourceLocation ScopeLoc, Form FormUsed)
+ : AttributeCommonInfo(
+ AttrName, ScopeName, AttrRange, ScopeLoc,
+ getParsedKind(AttrName, ScopeName, FormUsed.getSyntax()),
+ FormUsed) {}
AttributeCommonInfo(const IdentifierInfo *AttrName, SourceRange AttrRange,
Form FormUsed)
- : AttrName(AttrName), ScopeName(nullptr), AttrRange(AttrRange),
- ScopeLoc(),
- AttrKind(getParsedKind(AttrName, ScopeName, FormUsed.getSyntax())),
- SyntaxUsed(FormUsed.getSyntax()),
- SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ : AttributeCommonInfo(AttrName, nullptr, AttrRange, ScopeLoc(),
+ FormUsed) {}
AttributeCommonInfo(SourceRange AttrRange, Kind K, Form FormUsed)
- : AttrName(nullptr), ScopeName(nullptr), AttrRange(AttrRange),
ScopeLoc(),
- AttrKind(K), SyntaxUsed(FormUsed.getSyntax()),
- SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ : AttributeCommonInfo(nullptr, nullptr, AttrRange, ScopeLoc(), K,
+ FormUsed) {}
AttributeCommonInfo(AttributeCommonInfo &&) = default;
AttributeCommonInfo(const AttributeCommonInfo &) = default;
Index: clang/include/clang/Basic/AttributeCommonInfo.h
===================================================================
--- clang/include/clang/Basic/AttributeCommonInfo.h
+++ clang/include/clang/Basic/AttributeCommonInfo.h
@@ -25,7 +25,7 @@
/// The style used to specify an attribute.
enum Syntax {
/// __attribute__((...))
- AS_GNU,
+ AS_GNU = 1,
/// [[...]]
AS_CXX11,
@@ -122,37 +122,32 @@
AttributeCommonInfo(const IdentifierInfo *AttrName,
const IdentifierInfo *ScopeName, SourceRange AttrRange,
- SourceLocation ScopeLoc, Form FormUsed)
+ SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
: AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange),
- ScopeLoc(ScopeLoc),
- AttrKind(getParsedKind(AttrName, ScopeName, FormUsed.getSyntax())),
+ ScopeLoc(ScopeLoc), AttrKind(AttrKind),
SyntaxUsed(FormUsed.getSyntax()),
SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ IsAlignas(FormUsed.isAlignas()) {
+ assert(SyntaxUsed >= AS_GNU && SyntaxUsed <= AS_Implicit &&
+ "Invalid syntax!");
+ }
AttributeCommonInfo(const IdentifierInfo *AttrName,
const IdentifierInfo *ScopeName, SourceRange AttrRange,
- SourceLocation ScopeLoc, Kind AttrKind, Form FormUsed)
- : AttrName(AttrName), ScopeName(ScopeName), AttrRange(AttrRange),
- ScopeLoc(ScopeLoc), AttrKind(AttrKind),
- SyntaxUsed(FormUsed.getSyntax()),
- SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ SourceLocation ScopeLoc, Form FormUsed)
+ : AttributeCommonInfo(
+ AttrName, ScopeName, AttrRange, ScopeLoc,
+ getParsedKind(AttrName, ScopeName, FormUsed.getSyntax()),
+ FormUsed) {}
AttributeCommonInfo(const IdentifierInfo *AttrName, SourceRange AttrRange,
Form FormUsed)
- : AttrName(AttrName), ScopeName(nullptr), AttrRange(AttrRange),
- ScopeLoc(),
- AttrKind(getParsedKind(AttrName, ScopeName, FormUsed.getSyntax())),
- SyntaxUsed(FormUsed.getSyntax()),
- SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ : AttributeCommonInfo(AttrName, nullptr, AttrRange, ScopeLoc(),
+ FormUsed) {}
AttributeCommonInfo(SourceRange AttrRange, Kind K, Form FormUsed)
- : AttrName(nullptr), ScopeName(nullptr), AttrRange(AttrRange), ScopeLoc(),
- AttrKind(K), SyntaxUsed(FormUsed.getSyntax()),
- SpellingIndex(FormUsed.getSpellingIndex()),
- IsAlignas(FormUsed.isAlignas()) {}
+ : AttributeCommonInfo(nullptr, nullptr, AttrRange, ScopeLoc(), K,
+ FormUsed) {}
AttributeCommonInfo(AttributeCommonInfo &&) = default;
AttributeCommonInfo(const AttributeCommonInfo &) = default;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits