Skip to content

Commit

Permalink
View types should not be const or volatile
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxSciurorum authored and neboat committed Dec 4, 2024
1 parent c06a130 commit b8f1847
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;

Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 12 additions & 0 deletions clang/test/Cilk/hyper-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}

0 comments on commit b8f1847

Please sign in to comment.