[clang] [clang] Instantiate attributes on other decl types (PR #115924)
Eric Astor via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 12 10:49:24 PST 2024
https://github.com/ericastor created https://github.com/llvm/llvm-project/pull/115924
Start propagating attributes on (e.g.) labels inside of templated functions to their instances.
>From da2e66a6a2636bf1a1ab2e25afdbd29095b6db3f Mon Sep 17 00:00:00 2001
From: Eric Astor <epastor at google.com>
Date: Tue, 12 Nov 2024 17:37:42 +0000
Subject: [PATCH] [clang] Instantiate attributes on other decl types
Start propagating attributes on (e.g.) labels inside of templated functions to their instances.
---
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 16 +++++++++++++---
clang/test/SemaCXX/attr-mode-tmpl.cpp | 4 ++--
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..bfc5913dbafd0f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -990,6 +990,7 @@ Decl *
TemplateDeclInstantiator::VisitLabelDecl(LabelDecl *D) {
LabelDecl *Inst = LabelDecl::Create(SemaRef.Context, Owner, D->getLocation(),
D->getIdentifier());
+ SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
Owner->addDecl(Inst);
return Inst;
}
@@ -1009,6 +1010,7 @@ TemplateDeclInstantiator::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
D->getQualifierLoc(),
D->getTargetNameLoc(),
D->getNamespace());
+ SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
Owner->addDecl(Inst);
return Inst;
}
@@ -1095,15 +1097,21 @@ Decl *TemplateDeclInstantiator::InstantiateTypedefNameDecl(TypedefNameDecl *D,
Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/false);
- if (Typedef)
+ if (Typedef) {
+ SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef, LateAttrs,
+ StartingScope);
Owner->addDecl(Typedef);
+ }
return Typedef;
}
Decl *TemplateDeclInstantiator::VisitTypeAliasDecl(TypeAliasDecl *D) {
Decl *Typedef = InstantiateTypedefNameDecl(D, /*IsTypeAlias=*/true);
- if (Typedef)
+ if (Typedef) {
+ SemaRef.InstantiateAttrs(TemplateArgs, D, Typedef, LateAttrs,
+ StartingScope);
Owner->addDecl(Typedef);
+ }
return Typedef;
}
@@ -1160,8 +1168,10 @@ Decl *TemplateDeclInstantiator::InstantiateTypeAliasTemplateDecl(
Decl *
TemplateDeclInstantiator::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
Decl *Inst = InstantiateTypeAliasTemplateDecl(D);
- if (Inst)
+ if (Inst) {
+ SemaRef.InstantiateAttrs(TemplateArgs, D, Inst, LateAttrs, StartingScope);
Owner->addDecl(Inst);
+ }
return Inst;
}
diff --git a/clang/test/SemaCXX/attr-mode-tmpl.cpp b/clang/test/SemaCXX/attr-mode-tmpl.cpp
index f665b1ba491237..58266f947051c5 100644
--- a/clang/test/SemaCXX/attr-mode-tmpl.cpp
+++ b/clang/test/SemaCXX/attr-mode-tmpl.cpp
@@ -9,7 +9,7 @@ void CheckEnumerations() {
// Check that non-vector 'mode' attribute is OK with enumeration types.
typedef T __attribute__((mode(QI))) T1;
typedef T T2 __attribute__((mode(HI)));
- typedef T __attribute__((mode(V8SI))) T3; // expected-error{{mode 'V8SI' is not supported for enumeration types}}
+ typedef T __attribute__((mode(V8SI))) T3; // expected-error2{{mode 'V8SI' is not supported for enumeration types}}
// expected-warning at -1{{specifying vector types with the 'mode' attribute is deprecated}}
typedef enum __attribute__((mode(HI))) { A4, B4 } T4;
@@ -62,7 +62,7 @@ struct TemplatedStruct {
// Check typedefs.
typedef T __attribute__((mode(DI))) T1;
- typedef T __attribute__((mode(V8DI))) T2; // expected-error{{mode 'V8DI' is not supported for enumeration types}}
+ typedef T __attribute__((mode(V8DI))) T2; // expected-error2{{mode 'V8DI' is not supported for enumeration types}}
// expected-warning at -1{{deprecated}}
// Check parameters.
More information about the cfe-commits
mailing list