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.

- 'msvc::no_tls_guard', first appeared in MSVC toolchain 14.25.28610
- 'msvc::known_semantics', first appeared in MSVC toolchain 14.27.29110
- 'msvc::noop_dtor', first appeared in MSVC toolchain 14.28.29333
- 'msvc::constexpr', first appeared in MSVC toolchain 14.33.31629

Closes #57696


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133853

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaStmtAttr.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,9 @@
 // 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: MSNoTlsGuard (SubjectMatchRule_variable)
+// CHECK-NEXT: MSNoopDtor (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,35 @@
+// RUN: %clang_cc1 -fms-extensions -std=c++20 -DMSX -ast-dump %s | FileCheck %s
+// RUN: not %clang_cc1 -Werror=ignored-attributes -ast-dump %s 2>&1 | grep "8 errors generated"
+
+// CHECK: VarDecl 0x{{[0-9a-f]+}} <{{.*}}:[[@LINE+3]]:24, col:47> col:47 no_tls_guard_var
+// CHECK-NEXT: MSNoTlsGuardAttr 0x{{[0-9a-f]+}} <col:3, col:9>
+// CHECK-NEXT: ThreadAttr 0x{{[0-9a-f]+}} <col:35>
+[[msvc::no_tls_guard]] __declspec(thread) int no_tls_guard_var;
+
+// CHECK: MSKnownSemanticsAttr 0x{{[0-9a-f]+}} <col:10, col:16>
+// CHECK-NEXT: CXXRecordDecl 0x{{[0-9a-f]+}} <col:1, col:34> col:34
+struct [[msvc::known_semantics]] Struct {};
+
+// CHECK: TypeAliasDecl 0x{{[0-9a-f]+}} <line:[[@LINE+3]]:1, col:39> col:7 Int 'int'
+// CHECK-NEXT: BuiltinType 0x{{[0-9a-f]+}} 'int'
+// CHECK-NEXT: MSKnownSemanticsAttr 0x{{[0-9a-f]+}} <col:13, col:19>
+using Int [[msvc::known_semantics]] = int;
+
+struct Dtor {
+  // CHECK: CXXDestructorDecl 0x{{[0-9a-f]+}} <line:[[@LINE+3]]:23, col:32> col:23 ~Dtor 'void () noexcept'
+  // CHECK-NEXT: CompoundStmt 0x{{[0-9a-f]+}} <col:31, col:32>
+  // CHECK-NEXT: MSNoopDtorAttr 0x{{[0-9a-f]+}} <col:5, col:11>
+  [[msvc::noop_dtor]] ~Dtor() {}
+};
+
+// CHECK: FunctionDecl 0x{{[0-9a-f]+}} <line:[[@LINE+2]]:21, col:61> col:27 New1 'void *(void *)'
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} <col:3, col:9>
+[[msvc::constexpr]] void *New1(void *where) { return where; }
+
+// CHECK: FunctionDecl {{.*}} <line:[[@LINE+4]]:1, line:[[@LINE+6]]:1> line:[[@LINE+4]]:17 constexpr New2
+// CHECK-NEXT: CompoundStmt
+// CHECK-NEXT: AttributedStmt
+// CHECK-NEXT: MSConstexprAttr
+constexpr char *New2() {
+  [[msvc::constexpr]] return ::new char[1];
+}
Index: clang/lib/Sema/SemaStmtAttr.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -290,6 +290,12 @@
   return ::new (S.Context) UnlikelyAttr(S.Context, A);
 }
 
+static Attr *handleMSConstexpr(Sema &S, Stmt *St, const ParsedAttr &A,
+                               SourceRange Range) {
+  // Validation is in Sema::ActOnAttributedStmt().
+  return ::new (S.Context) MSConstexprAttr(S.Context, A);
+}
+
 #define WANT_STMT_MERGE_LOGIC
 #include "clang/Sema/AttrParsedAttrImpl.inc"
 #undef WANT_STMT_MERGE_LOGIC
@@ -485,6 +491,8 @@
     return handleLikely(S, St, A, Range);
   case ParsedAttr::AT_Unlikely:
     return handleUnlikely(S, St, A, Range);
+  case ParsedAttr::AT_MSConstexpr:
+    return handleMSConstexpr(S, St, A, Range);
   default:
     // N.B., ClangAttrEmitter.cpp emits a diagnostic helper that ensures a
     // declaration attribute is not written on a statement, but this code is
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1745,6 +1745,7 @@
   case attr::AddressSpace:
   case attr::CmseNSCall:
   case attr::AnnotateType:
+  case attr::MSKnownSemantics:
     llvm_unreachable("This attribute should have been handled already");
 
   case attr::NSReturnsRetained:
Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3478,6 +3478,41 @@
 }];
 }
 
+def MSNoTlsGuardDocs : Documentation {
+  let Category = DocCatVariable;
+  let Content = [{
+This attribute can be added to a TLS variable to disable initialization
+test check in threads which existed before DLL was loaded.
+It applies behavior of '/Zc:tlsGuards-' flag to the variable.
+Has no effect on clang.
+  }];
+}
+
+def MSKnownSemanticsDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute tells MSVC compiler that the type trait specialization
+have the standard-mandated semantics.
+Has no effect on clang.
+  }];
+}
+
+def MSNoopDtorDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+This attribute tells MSVC compiler that the destructor have no effects.
+Has no effect on clang.
+  }];
+}
+
+def MSConstexprDocs : Documentation {
+  let Category = DocCatStmt;
+  let Content = [{
+This attribute allows MSVC compiler to use "externed constexpr".
+Has no effect on clang.
+  }];
+}
+
 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
@@ -3487,6 +3487,38 @@
 
 // Microsoft-related attributes
 
+def MSNoTlsGuard : InheritableAttr {
+  let LangOpts = [MicrosoftExt];
+  let Spellings = [CXX11<"msvc", "no_tls_guard">];
+  let Subjects = SubjectList<[Var], ErrorDiag>;
+  let Documentation = [MSNoTlsGuardDocs];
+  let SimpleHandler = 1;
+}
+
+def MSKnownSemantics : TypeAttr {
+  let LangOpts = [MicrosoftExt];
+  let Spellings = [CXX11<"msvc", "known_semantics">];
+  let Documentation = [MSKnownSemanticsDocs];
+  let SimpleHandler = 1;
+}
+
+def MSNoopDtor : InheritableAttr {
+  let LangOpts = [MicrosoftExt];
+  let Spellings = [CXX11<"msvc", "noop_dtor">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let Documentation = [MSNoopDtorDocs];
+  let SimpleHandler = 1;
+}
+
+def MSConstexpr : DeclOrStmtAttr {
+  let LangOpts = [MicrosoftExt];
+  let Spellings = [CXX11<"msvc", "constexpr">];
+  let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
+                             "functions and statements">;
+  let Documentation = [MSConstexprDocs];
+  let SimpleHandler = 1;
+}
+
 def MSNoVTable : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
   let Spellings = [Declspec<"novtable">];
   let Subjects = SubjectList<[CXXRecord]>;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to