Skip to content

Commit 8dda4c1

Browse files
committed
[clang][ExprConst] Can't be past an invalid LValue designator
1 parent b1f2e19 commit 8dda4c1

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9211,7 +9211,8 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
92119211
Info.getLangOpts().CPlusPlus26)) {
92129212
// Permitted.
92139213
} else {
9214-
if (SubExpr->getType()->isVoidPointerType()) {
9214+
if (SubExpr->getType()->isVoidPointerType() &&
9215+
Info.getLangOpts().CPlusPlus) {
92159216
if (HasValidResult)
92169217
CCEDiag(E, diag::note_constexpr_invalid_void_star_cast)
92179218
<< SubExpr->getType() << Info.getLangOpts().CPlusPlus26
@@ -12899,6 +12900,10 @@ static bool isOnePastTheEndOfCompleteObject(const ASTContext &Ctx,
1289912900
if (Ty->isIncompleteType())
1290012901
return true;
1290112902

12903+
// Can't be past the end of an invalid object.
12904+
if (LV.getLValueDesignator().Invalid)
12905+
return false;
12906+
1290212907
// We're a past-the-end pointer if we point to the byte after the object,
1290312908
// no matter what our type or path is.
1290412909
auto Size = Ctx.getTypeSizeInChars(Ty);

clang/test/AST/Interp/c.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ _Static_assert((&a - 100) != 0, ""); // pedantic-ref-warning {{is a GNU extensio
6666
// pedantic-ref-note {{-100 of non-array}} \
6767
// pedantic-expected-note {{-100 of non-array}}
6868
/// extern variable of a composite type.
69-
/// FIXME: The 'cast from void*' note is missing in the new interpreter.
69+
/// FIXME: The 'this conversion is not allowed' note is missing in the new interpreter.
7070
extern struct Test50S Test50;
7171
_Static_assert(&Test50 != (void*)0, ""); // all-warning {{always true}} \
7272
// pedantic-ref-warning {{is a GNU extension}} \
73-
// pedantic-ref-note {{cast from 'void *' is not allowed}} \
73+
// pedantic-ref-note {{this conversion is not allowed in a constant expression}} \
7474
// pedantic-expected-warning {{is a GNU extension}}
7575

7676
struct y {int x,y;};

clang/test/Sema/const-eval.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ void PR21945(void) { int i = (({}), 0l); }
134134

135135
void PR24622(void);
136136
struct PR24622 {} pr24622;
137-
EVAL_EXPR(52, &pr24622 == (void *)&PR24622); // expected-error {{not an integer constant expression}}
138-
// expected-note@-1 {{past the end}}
137+
EVAL_EXPR(52, &pr24622 == (void *)&PR24622);
139138

140139
// We evaluate these by providing 2s' complement semantics in constant
141140
// expressions, like we do for integers.

clang/test/Sema/constexpr-void-cast.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -x c -fsyntax-only %s -verify=c
2+
// RUN: %clang_cc1 -x c -fsyntax-only %s -pedantic -verify=c-pedantic
3+
//
4+
// RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify=cxx
5+
// RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx-pedantic
6+
7+
// c-no-diagnostics
8+
// cxx-no-diagnostics
9+
10+
void f(void);
11+
struct S {char c;} s;
12+
_Static_assert(&s != (void *)&f, ""); // c-pedantic-warning {{not an integer constant expression}} \
13+
// c-pedantic-note {{this conversion is not allowed in a constant expression}} \
14+
// cxx-pedantic-warning {{'_Static_assert' is a C11 extension}}

0 commit comments

Comments
 (0)