diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 77f1b9b0d707..2aeaecf9cd90 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10892,6 +10892,9 @@ def confusing_hyperobject : Error< def incomplete_hyperobject : Error< "incomplete type %0 may not be a hyperobject">; +def qualified_hyperobject : Error< + "qualified type %0 may not be a hyperobject">; + def nested_hyperobject : Error< "type %0, which contains a hyperobject, may not be a hyperobject">; diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 63ac68a39f96..ad2110207729 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -2495,6 +2495,12 @@ QualType Sema::BuildHyperobjectType(QualType Element, Expr *Identity, Diag(Loc, *Code) << Element; } + if (Element.isConstQualified() || Element.isVolatileQualified()) { + Diag(Loc, diag::qualified_hyperobject) << Element; + // Volatile reducers generate confusing diagnostics when used. + Element.removeLocalVolatile(); + } + Identity = ValidateReducerCallback(Identity, 1, Loc); Reduce = ValidateReducerCallback(Reduce, 2, Loc); diff --git a/clang/test/Cilk/hyper-errors.c b/clang/test/Cilk/hyper-errors.c index 5458face1382..c342a82df0cd 100644 --- a/clang/test/Cilk/hyper-errors.c +++ b/clang/test/Cilk/hyper-errors.c @@ -37,4 +37,16 @@ void function() { // expected-error@-2{{use of undeclared identifier 'typo3'}} int _Hyperobject(0, typo4) var3 = 0; // expected-error@-1{{use of undeclared identifier 'typo4'}} + const int _Hyperobject(identity, reduce) var4 = 0; + // expected-error@-1{{qualified type 'const int' may not be a hyperobject}} + volatile int _Hyperobject(identity, reduce) var5 = 0; + // expected-error@-1{{qualified type 'volatile int' may not be a hyperobject}} + typedef const int c_int; + c_int _Hyperobject(identity, reduce) var6 = 0; + // expected-error@-1{{qualified type 'c_int' (aka 'const int') may not be a hyperobject}} + ++var4; + // expected-error@-1{{read-only variable is not assignable}} + ++var5; + ++var6; + // expected-error@-1{{read-only variable is not assignable}} }