aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorEric Astor <epastor@google.com>2024-10-10 12:21:34 -0400
committerGitHub <noreply@github.com>2024-10-10 12:21:34 -0400
commit73e74e496ec32a13a5ae71df71364065f7be3cca (patch)
tree0e0c95893db77546991e4270fffad58507c7ea05 /clang/lib/Sema/Sema.cpp
parent2190ffa0f7e874d04fd0f750142135faa5df5d6b (diff)
downloadllvm-73e74e496ec32a13a5ae71df71364065f7be3cca.zip
llvm-73e74e496ec32a13a5ae71df71364065f7be3cca.tar.gz
llvm-73e74e496ec32a13a5ae71df71364065f7be3cca.tar.bz2
[clang][frontend] Support applying the annotate attribute to statements (#111841)
By allowing AnnotateAttr to be applied to statements, users can place arbitrary information in the AST for later use. For example, this can be used for HW-targeted language extensions that involve specialized loop annotations.
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r--clang/lib/Sema/Sema.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index f057604..9f91ee9 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -2777,3 +2777,31 @@ bool Sema::isDeclaratorFunctionLike(Declarator &D) {
});
return Result;
}
+
+Attr *Sema::CreateAnnotationAttr(const AttributeCommonInfo &CI, StringRef Annot,
+ MutableArrayRef<Expr *> Args) {
+
+ auto *A = AnnotateAttr::Create(Context, Annot, Args.data(), Args.size(), CI);
+ if (!ConstantFoldAttrArgs(
+ CI, MutableArrayRef<Expr *>(A->args_begin(), A->args_end()))) {
+ return nullptr;
+ }
+ return A;
+}
+
+Attr *Sema::CreateAnnotationAttr(const ParsedAttr &AL) {
+ // Make sure that there is a string literal as the annotation's first
+ // argument.
+ StringRef Str;
+ if (!checkStringLiteralArgumentAttr(AL, 0, Str))
+ return nullptr;
+
+ llvm::SmallVector<Expr *, 4> Args;
+ Args.reserve(AL.getNumArgs() - 1);
+ for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
+ assert(!AL.isArgIdent(Idx));
+ Args.push_back(AL.getArgAsExpr(Idx));
+ }
+
+ return CreateAnnotationAttr(AL, Str, Args);
+}