[clang] adb290d - [Sema][SVE] Reject atomic sizeless types

Richard Sandiford via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 12 10:27:51 PDT 2020


Author: Richard Sandiford
Date: 2020-03-12T17:20:23Z
New Revision: adb290d97482aa9311ee4b4b5917a0f2ece55b30

URL: https://github.com/llvm/llvm-project/commit/adb290d97482aa9311ee4b4b5917a0f2ece55b30
DIFF: https://github.com/llvm/llvm-project/commit/adb290d97482aa9311ee4b4b5917a0f2ece55b30.diff

LOG: [Sema][SVE] Reject atomic sizeless types

It would be difficult to guarantee atomicity for sizeless types,
so the SVE ACLE makes atomic sizeless types invalid.  As it happens,
we already rejected them before the patch, but for the wrong reason:

  error: _Atomic cannot be applied to type 'svint8_t' (aka '__SVInt8_t')
  which is not trivially copyable

The SVE types should be treated as trivially copyable; a later
patch fixes that.

Differential Revision: https://reviews.llvm.org/D75734

Added: 
    

Modified: 
    clang/include/clang/Basic/DiagnosticSemaKinds.td
    clang/lib/Sema/SemaType.cpp
    clang/test/Sema/sizeless-1.c
    clang/test/SemaCXX/sizeless-1.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fe0f9e959a1b..830787e2663c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5925,7 +5925,7 @@ def err_func_def_incomplete_result : Error<
   "incomplete result type %0 in function definition">;
 def err_atomic_specifier_bad_type : Error<
   "_Atomic cannot be applied to "
-  "%select{incomplete |array |function |reference |atomic |qualified |}0type "
+  "%select{incomplete |array |function |reference |atomic |qualified |sizeless |}0type "
   "%1 %select{||||||which is not trivially copyable}0">;
 
 // Expressions.

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1d9826f1970d..f7da1b13a1bf 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8564,9 +8564,11 @@ QualType Sema::BuildAtomicType(QualType T, SourceLocation Loc) {
       DisallowedKind = 4;
     else if (T.hasQualifiers())
       DisallowedKind = 5;
+    else if (T->isSizelessType())
+      DisallowedKind = 6;
     else if (!T.isTriviallyCopyableType(Context))
       // Some other non-trivially-copyable type (probably a C++ class)
-      DisallowedKind = 6;
+      DisallowedKind = 7;
 
     if (DisallowedKind != -1) {
       Diag(Loc, diag::err_atomic_specifier_bad_type) << DisallowedKind << T;

diff  --git a/clang/test/Sema/sizeless-1.c b/clang/test/Sema/sizeless-1.c
index 3e3c3259681a..c33aba8e2e55 100644
--- a/clang/test/Sema/sizeless-1.c
+++ b/clang/test/Sema/sizeless-1.c
@@ -84,6 +84,7 @@ void func(int sel) {
   const volatile svint8_t const_volatile_int8 = local_int8; // expected-note {{declared const here}}
   const volatile svint8_t uninit_const_volatile_int8;
 
+  _Atomic svint8_t atomic_int8;      // expected-error {{_Atomic cannot be applied to sizeless type 'svint8_t'}}
   __restrict svint8_t restrict_int8; // expected-error {{requires a pointer or reference}}
 
   _Bool test_int8 = init_int8; // expected-error {{initializing '_Bool' with an expression of incompatible type 'svint8_t'}}

diff  --git a/clang/test/SemaCXX/sizeless-1.cpp b/clang/test/SemaCXX/sizeless-1.cpp
index 638eb523ac9c..dda36fdbd0d4 100644
--- a/clang/test/SemaCXX/sizeless-1.cpp
+++ b/clang/test/SemaCXX/sizeless-1.cpp
@@ -98,6 +98,7 @@ void func(int sel) {
   const volatile svint8_t const_volatile_int8 = local_int8; // expected-note {{declared const here}}
   const volatile svint8_t uninit_const_volatile_int8;       // expected-error {{default initialization of an object of const type 'const volatile svint8_t'}}
 
+  _Atomic svint8_t atomic_int8;      // expected-error {{_Atomic cannot be applied to sizeless type 'svint8_t'}}
   __restrict svint8_t restrict_int8; // expected-error {{requires a pointer or reference}}
 
   bool test_int8 = init_int8; // expected-error {{cannot initialize a variable of type 'bool' with an lvalue of type 'svint8_t'}}


        


More information about the cfe-commits mailing list