[PATCH] D134475: [AST] Add C++11 attribute msvc::constexpr
Richard Dzenis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 22 13:48:16 PDT 2022
RIscRIpt created this revision.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
RIscRIpt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134475
Files:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/AST/msvc-attrs.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===================================================================
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -83,6 +83,7 @@
// CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global)
// CHECK-NEXT: Lockable (SubjectMatchRule_record)
// CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
+// CHECK-NEXT: MSConstexpr (SubjectMatchRule_function)
// CHECK-NEXT: MSStruct (SubjectMatchRule_record)
// CHECK-NEXT: MaybeUndef (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: MicroMips (SubjectMatchRule_function)
Index: clang/test/AST/msvc-attrs.cpp
===================================================================
--- /dev/null
+++ clang/test/AST/msvc-attrs.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -ast-dump %s | FileCheck %s
+// RUN: not %clang_cc1 -Werror=ignored-attributes -ast-dump %s 2> %t.stderr.txt
+// RUN: FileCheck -check-prefix CHECK-DIAG-NO-MSX %s < %t.stderr.txt
+
+// CHECK: msvc-attrs.cpp:[[@LINE+3]]:21, col:61> col:27 constexpr New1 'void *(void *)'
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} <col:3, col:9>
+// CHECK-DIAG-NO-MSX: msvc-attrs.cpp:[[@LINE+1]]:3: error: 'constexpr' attribute ignored
+[[msvc::constexpr]] void *New1(void *where) { return where; }
Index: clang/lib/Sema/SemaDeclAttr.cpp
===================================================================
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -4992,6 +4992,9 @@
case ParsedAttr::AT_PreserveAll:
D->addAttr(::new (S.Context) PreserveAllAttr(S.Context, AL));
return;
+ case ParsedAttr::AT_MSConstexpr:
+ D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
+ return;
default:
llvm_unreachable("unexpected attribute kind");
}
@@ -7050,6 +7053,12 @@
D->addAttr(::new (S.Context) ThreadAttr(S.Context, AL));
}
+static void handleMSConstexprAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
+ if (auto *FD = dyn_cast<FunctionDecl>(D))
+ FD->setConstexprKind(ConstexprSpecKind::Constexpr);
+ D->addAttr(::new (S.Context) MSConstexprAttr(S.Context, AL));
+}
+
static void handleAbiTagAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
SmallVector<StringRef, 4> Tags;
for (unsigned I = 0, E = AL.getNumArgs(); I != E; ++I) {
@@ -8987,6 +8996,9 @@
case ParsedAttr::AT_Thread:
handleDeclspecThreadAttr(S, D, AL);
break;
+ case ParsedAttr::AT_MSConstexpr:
+ handleMSConstexprAttr(S, D, AL);
+ break;
// HLSL attributes:
case ParsedAttr::AT_HLSLNumThreads:
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3478,6 +3478,14 @@
}];
}
+def MSConstexprDocs : Documentation {
+ let Category = DocCatStmt;
+ let Content = [{
+This attribute is an alias of ``constexpr`` for functions.
+Available only as Microsoft extension (``-fms-extensions``).
+ }];
+}
+
def MSNoVTableDocs : Documentation {
let Category = DocCatDecl;
let Content = [{
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -3500,6 +3500,13 @@
// Microsoft-related attributes
+def MSConstexpr : InheritableAttr {
+ let LangOpts = [MicrosoftExt];
+ let Spellings = [CXX11<"msvc", "constexpr">];
+ let Subjects = SubjectList<[Function]>;
+ let Documentation = [MSConstexprDocs];
+}
+
def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
let Spellings = [Declspec<"novtable">];
let Subjects = SubjectList<[CXXRecord]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134475.462283.patch
Type: text/x-patch
Size: 3883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220922/b349a331/attachment.bin>
More information about the cfe-commits
mailing list