Skip to content

Commit 552c6c2

Browse files
committed
PR44406: Follow behavior of array bound constant folding in more recent versions of GCC.
Old GCC used to aggressively fold VLAs to constant-bound arrays at block scope in GNU mode. That's non-conforming, and more modern versions of GCC only do this at file scope. Update Clang to do the same. Also promote the warning for this from off-by-default to on-by-default in all cases; more recent versions of GCC likewise warn on this by default. This is still slightly more permissive than GCC, as pointed out in PR44406, as we still fold VLAs to constant arrays in structs, but that seems justifiable given that we don't support VLA-in-struct (and don't intend to ever support it), but GCC does. Differential Revision: https://reviews.llvm.org/D89523
1 parent 1091130 commit 552c6c2

32 files changed

+135
-95
lines changed

clang/docs/UsersManual.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,10 +2502,6 @@ Differences between all ``c*`` and ``gnu*`` modes:
25022502
- The Apple "blocks" extension is recognized by default in ``gnu*`` modes
25032503
on some platforms; it can be enabled in any mode with the ``-fblocks``
25042504
option.
2505-
- Arrays that are VLA's according to the standard, but which can be
2506-
constant folded by the frontend are treated as fixed size arrays.
2507-
This occurs for things like "int X[(1, 2)];", which is technically a
2508-
VLA. ``c*`` modes are strictly compliant and treat these as VLAs.
25092505

25102506
Differences between ``*89`` and ``*94`` modes:
25112507

@@ -2594,10 +2590,12 @@ Intentionally unsupported GCC extensions
25942590
the extension appears to be rarely used. Note that clang *does*
25952591
support flexible array members (arrays with a zero or unspecified
25962592
size at the end of a structure).
2597-
- clang does not have an equivalent to gcc's "fold"; this means that
2598-
clang doesn't accept some constructs gcc might accept in contexts
2599-
where a constant expression is required, like "x-x" where x is a
2600-
variable.
2593+
- GCC accepts many expression forms that are not valid integer constant
2594+
expressions in bit-field widths, enumerator constants, case labels,
2595+
and in array bounds at global scope. Clang also accepts additional
2596+
expression forms in these contexts, but constructs that GCC accepts due to
2597+
simplifications GCC performs while parsing, such as ``x - x`` (where ``x`` is a
2598+
variable) will likely never be accepted by Clang.
26012599
- clang does not support ``__builtin_apply`` and friends; this extension
26022600
is extremely obscure and difficult to implement reliably.
26032601

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ def err_vla_decl_has_static_storage : Error<
137137
"variable length array declaration cannot have 'static' storage duration">;
138138
def err_vla_decl_has_extern_linkage : Error<
139139
"variable length array declaration cannot have 'extern' linkage">;
140-
def ext_vla_folded_to_constant : Extension<
141-
"variable length array folded to constant array as an extension">, InGroup<GNUFoldingConstant>;
140+
def ext_vla_folded_to_constant : ExtWarn<
141+
"variable length array folded to constant array as an extension">,
142+
InGroup<GNUFoldingConstant>;
142143
def err_vla_unsupported : Error<
143144
"variable length arrays are not supported for the current target">;
144145
def note_vla_unsupported : Note<
@@ -5474,8 +5475,6 @@ def warn_flag_enum_constant_out_of_range : Warning<
54745475
"enumeration value %0 is out of range of flags in enumeration type %1">,
54755476
InGroup<FlagEnum>;
54765477

5477-
def warn_illegal_constant_array_size : Extension<
5478-
"size of static array must be an integer constant expression">;
54795478
def err_vm_decl_in_file_scope : Error<
54805479
"variably modified type declaration not allowed at file scope">;
54815480
def err_vm_decl_has_extern_linkage : Error<

clang/lib/Sema/SemaDecl.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5932,9 +5932,14 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
59325932
const VariableArrayType* VLATy = dyn_cast<VariableArrayType>(T);
59335933
if (!VLATy)
59345934
return QualType();
5935-
// FIXME: We should probably handle this case
5936-
if (VLATy->getElementType()->isVariablyModifiedType())
5937-
return QualType();
5935+
5936+
QualType ElemTy = VLATy->getElementType();
5937+
if (ElemTy->isVariablyModifiedType()) {
5938+
ElemTy = TryToFixInvalidVariablyModifiedType(ElemTy, Context,
5939+
SizeIsNegative, Oversized);
5940+
if (ElemTy.isNull())
5941+
return QualType();
5942+
}
59385943

59395944
Expr::EvalResult Result;
59405945
if (!VLATy->getSizeExpr() ||
@@ -5950,16 +5955,18 @@ static QualType TryToFixInvalidVariablyModifiedType(QualType T,
59505955
}
59515956

59525957
// Check whether the array is too large to be addressed.
5953-
unsigned ActiveSizeBits
5954-
= ConstantArrayType::getNumAddressingBits(Context, VLATy->getElementType(),
5955-
Res);
5958+
unsigned ActiveSizeBits =
5959+
(!ElemTy->isDependentType() && !ElemTy->isVariablyModifiedType() &&
5960+
!ElemTy->isIncompleteType() && !ElemTy->isUndeducedType())
5961+
? ConstantArrayType::getNumAddressingBits(Context, ElemTy, Res)
5962+
: Res.getActiveBits();
59565963
if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) {
59575964
Oversized = Res;
59585965
return QualType();
59595966
}
59605967

5961-
return Context.getConstantArrayType(
5962-
VLATy->getElementType(), Res, VLATy->getSizeExpr(), ArrayType::Normal, 0);
5968+
return Context.getConstantArrayType(ElemTy, Res, VLATy->getSizeExpr(),
5969+
ArrayType::Normal, 0);
59635970
}
59645971

59655972
static void
@@ -5985,7 +5992,13 @@ FixInvalidVariablyModifiedTypeLoc(TypeLoc SrcTL, TypeLoc DstTL) {
59855992
ArrayTypeLoc DstATL = DstTL.castAs<ArrayTypeLoc>();
59865993
TypeLoc SrcElemTL = SrcATL.getElementLoc();
59875994
TypeLoc DstElemTL = DstATL.getElementLoc();
5988-
DstElemTL.initializeFullCopy(SrcElemTL);
5995+
if (VariableArrayTypeLoc SrcElemATL =
5996+
SrcElemTL.getAs<VariableArrayTypeLoc>()) {
5997+
ConstantArrayTypeLoc DstElemATL = DstElemTL.castAs<ConstantArrayTypeLoc>();
5998+
FixInvalidVariablyModifiedTypeLoc(SrcElemATL, DstElemATL);
5999+
} else {
6000+
DstElemTL.initializeFullCopy(SrcElemTL);
6001+
}
59896002
DstATL.setLBracketLoc(SrcATL.getLBracketLoc());
59906003
DstATL.setSizeExpr(SrcATL.getSizeExpr());
59916004
DstATL.setRBracketLoc(SrcATL.getRBracketLoc());
@@ -6115,7 +6128,7 @@ Sema::CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *NewTD) {
61156128
SizeIsNegative,
61166129
Oversized);
61176130
if (FixedTInfo) {
6118-
Diag(NewTD->getLocation(), diag::warn_illegal_constant_array_size);
6131+
Diag(NewTD->getLocation(), diag::ext_vla_folded_to_constant);
61196132
NewTD->setTypeSourceInfo(FixedTInfo);
61206133
} else {
61216134
if (SizeIsNegative)
@@ -7984,7 +7997,7 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
79847997
return;
79857998
}
79867999

7987-
Diag(NewVD->getLocation(), diag::warn_illegal_constant_array_size);
8000+
Diag(NewVD->getLocation(), diag::ext_vla_folded_to_constant);
79888001
NewVD->setType(FixedT);
79898002
NewVD->setTypeSourceInfo(FixedTInfo);
79908003
}
@@ -16675,7 +16688,7 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
1667516688
SizeIsNegative,
1667616689
Oversized);
1667716690
if (FixedTInfo) {
16678-
Diag(Loc, diag::warn_illegal_constant_array_size);
16691+
Diag(Loc, diag::ext_vla_folded_to_constant);
1667916692
TInfo = FixedTInfo;
1668016693
T = FixedTInfo->getType();
1668116694
} else {

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,13 +2273,9 @@ static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
22732273
}
22742274
} Diagnoser(VLADiag, VLAIsError);
22752275

2276-
// FIXME: GCC does *not* allow folding here in general; see PR44406.
2277-
// For GCC compatibility, we should remove this folding and leave it to
2278-
// TryFixVariablyModifiedType to convert VLAs to constant array types.
22792276
ExprResult R = S.VerifyIntegerConstantExpression(
22802277
ArraySize, &SizeVal, Diagnoser,
2281-
(S.LangOpts.GNUMode || S.LangOpts.OpenCL) ? Sema::AllowFold
2282-
: Sema::NoFold);
2278+
S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
22832279
if (Diagnoser.IsVLA)
22842280
return ExprResult();
22852281
return R;

clang/test/CXX/basic/basic.types/p10.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ constexpr int f(ArrBad) { return 0; } // expected-error {{1st parameter type 'Ar
139139
constexpr int arb(int n) {
140140
int a[n]; // expected-error {{variable of non-literal type 'int [n]' cannot be defined in a constexpr function}}
141141
}
142+
// expected-warning@+1 {{variable length array folded to constant array as an extension}}
142143
constexpr long Overflow[ // expected-error {{constexpr variable cannot have non-literal type 'long const[(1 << 30) << 2]'}}
143144
(1 << 30) << 2]{}; // expected-warning {{requires 34 bits to represent}}
144145

clang/test/CXX/drs/dr3xx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,8 +898,8 @@ namespace dr367 { // dr367: yes
898898
int c[true ? *new int : 4]; // expected-error 2{{variable length array}} expected-note {{read of uninitialized}}
899899
int d[true ? 4 : *new int];
900900
#if __cplusplus < 201103L
901-
// expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}}
902-
// expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}}
901+
// expected-error@-4 2{{variable length array}}
902+
// expected-error@-3 2{{variable length array}}
903903
#endif
904904
}
905905

clang/test/CodeGen/vla.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,15 @@ void test9(int n, int a[static n]) { }
210210
void test10(int a[static 0]) {}
211211
// NULL-INVALID: define void @test10(i32* nonnull align 4 %a)
212212
// NULL-VALID: define void @test10(i32* align 4 %a)
213+
214+
const int constant = 32;
215+
// CHECK: define {{.*}}pr44406(
216+
int pr44406() {
217+
int n = 0;
218+
// Do not fold this VLA to an array of constant bound; that would miscompile
219+
// this testcase.
220+
char c[1][(constant - constant) + 3];
221+
// CHECK: store i32 1,
222+
sizeof(c[n = 1]);
223+
return n;
224+
}

clang/test/Misc/warning-flags.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ CHECK-NEXT: warn_weak_import
9191

9292
The list of warnings in -Wpedantic should NEVER grow.
9393

94-
CHECK: Number in -Wpedantic (not covered by other -W flags): 27
94+
CHECK: Number in -Wpedantic (not covered by other -W flags): 26

clang/test/PCH/cxx-constexpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const int b = a;
1616
#else
1717

1818
const int a = 5;
19-
typedef int T[b]; // expected-error {{variable length array}} expected-error {{must be an integer constant expression}} expected-note {{initializer of 'b'}}
19+
typedef int T[b]; // expected-error 2{{variable length array}} expected-note {{initializer of 'b'}}
2020
// expected-note@14 {{here}}
2121
typedef int T[5];
2222

clang/test/Profile/misexpect-switch-default.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void init_arry();
1010

1111
const int inner_loop = 1000;
1212
const int outer_loop = 20;
13-
const int arry_size = 25;
13+
enum { arry_size = 25 };
1414

1515
int arry[arry_size] = {0};
1616

clang/test/Profile/misexpect-switch-nonconst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void init_arry();
1111

1212
const int inner_loop = 1000;
1313
const int outer_loop = 20;
14-
const int arry_size = 25;
14+
enum { arry_size = 25 };
1515

1616
int arry[arry_size] = {0};
1717

clang/test/Profile/misexpect-switch-only-default-case.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void init_arry();
1111

1212
const int inner_loop = 1000;
1313
const int outer_loop = 20;
14-
const int arry_size = 25;
14+
enum { arry_size = 25 };
1515

1616
int arry[arry_size] = {0};
1717

clang/test/Profile/misexpect-switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void init_arry();
1010

1111
const int inner_loop = 1000;
1212
const int outer_loop = 20;
13-
const int arry_size = 25;
13+
enum { arry_size = 25 };
1414

1515
int arry[arry_size] = {0};
1616

clang/test/Sema/builtin-assume.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int foo(int *a, int i) {
2323
__builtin_assume(ispure(i) > 2);
2424
__builtin_assume(ispure(++i) > 2); //expected-warning {{the argument to '__builtin_assume' has side effects that will be discarded}}
2525

26-
int test = sizeof(struct{char qq[(__builtin_assume(i != 5), 7)];});
26+
int test = sizeof(struct{char qq[(__builtin_assume(i != 5), 7)];}); // expected-warning {{variable length array}}
2727
#endif
2828
return a[i];
2929
}

clang/test/Sema/builtins.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ typedef __typeof(sizeof(int)) size_t;
141141
size_t strlen(const char *);
142142

143143
void test17() {
144-
#define ASSERT(...) { int arr[(__VA_ARGS__) ? 1 : -1]; }
144+
#define ASSERT(...) { enum { folded = (__VA_ARGS__) }; int arr[folded ? 1 : -1]; }
145145
#define T(...) ASSERT(__builtin_constant_p(__VA_ARGS__))
146146
#define F(...) ASSERT(!__builtin_constant_p(__VA_ARGS__))
147147

@@ -179,12 +179,12 @@ void test17() {
179179
ASSERT(!OPT("abcd"));
180180
// In these cases, the strlen is non-constant, but the __builtin_constant_p
181181
// is 0: the array size is not an ICE but is foldable.
182-
ASSERT(!OPT(test17_c)); // expected-warning {{folded}}
183-
ASSERT(!OPT(&test17_c[0])); // expected-warning {{folded}}
184-
ASSERT(!OPT((char*)test17_c)); // expected-warning {{folded}}
185-
ASSERT(!OPT(test17_d)); // expected-warning {{folded}}
186-
ASSERT(!OPT(&test17_d[0])); // expected-warning {{folded}}
187-
ASSERT(!OPT((char*)test17_d)); // expected-warning {{folded}}
182+
ASSERT(!OPT(test17_c)); // expected-warning {{folding}}
183+
ASSERT(!OPT(&test17_c[0])); // expected-warning {{folding}}
184+
ASSERT(!OPT((char*)test17_c)); // expected-warning {{folding}}
185+
ASSERT(!OPT(test17_d)); // expected-warning {{folding}}
186+
ASSERT(!OPT(&test17_d[0])); // expected-warning {{folding}}
187+
ASSERT(!OPT((char*)test17_d)); // expected-warning {{folding}}
188188

189189
#undef OPT
190190
#undef T

clang/test/Sema/complex-int.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ void test5(_Complex int *x) {
6060
(*x)++;
6161
}
6262

63-
int i1[(2+3i)*(5+7i) == 29i-11 ? 1 : -1];
64-
int i2[(29i-11)/(5+7i) == 2+3i ? 1 : -1];
65-
int i3[-(2+3i) == +(-3i-2) ? 1 : -1];
66-
int i4[~(2+3i) == 2-3i ? 1 : -1];
67-
int i5[(3i == -(-3i) ? ((void)3, 1i - 1) : 0) == 1i - 1 ? 1 : -1];
63+
// None of these array bounds is an ICE due to the use of literals of
64+
// non-integer type. But we can constant-fold all of them.
65+
int i1[(2+3i)*(5+7i) == 29i-11 ? 1 : -1]; // expected-warning {{fold}}
66+
int i2[(29i-11)/(5+7i) == 2+3i ? 1 : -1]; // expected-warning {{fold}}
67+
int i3[-(2+3i) == +(-3i-2) ? 1 : -1]; // expected-warning {{fold}}
68+
int i4[~(2+3i) == 2-3i ? 1 : -1]; // expected-warning {{fold}}
69+
int i5[(3i == -(-3i) ? ((void)3, 1i - 1) : 0) == 1i - 1 ? 1 : -1]; // expected-warning {{fold}}
6870

69-
int f1[(2.0+3.0i)*(5.0+7.0i) == 29.0i-11.0 ? 1 : -1];
70-
int f2[(29.0i-11.0)/(5.0+7.0i) == 2.0+3.0i ? 1 : -1];
71-
int f3[-(2.0+3.0i) == +(-3.0i-2.0) ? 1 : -1];
72-
int f4[~(2.0+3.0i) == 2.0-3.0i ? 1 : -1];
73-
int f5[(3.0i == -(-3.0i) ? ((void)3.0, __extension__ (1.0i - 1.0)) : 0) == 1.0i - 1.0 ? 1 : -1];
71+
int f1[(2.0+3.0i)*(5.0+7.0i) == 29.0i-11.0 ? 1 : -1]; // expected-warning {{fold}}
72+
int f2[(29.0i-11.0)/(5.0+7.0i) == 2.0+3.0i ? 1 : -1]; // expected-warning {{fold}}
73+
int f3[-(2.0+3.0i) == +(-3.0i-2.0) ? 1 : -1]; // expected-warning {{fold}}
74+
int f4[~(2.0+3.0i) == 2.0-3.0i ? 1 : -1]; // expected-warning {{fold}}
75+
int f5[(3.0i == -(-3.0i) ? ((void)3.0, __extension__ (1.0i - 1.0)) : 0) == 1.0i - 1.0 ? 1 : -1]; // expected-warning {{fold}}

clang/test/Sema/const-eval-64.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux %s
2-
// expected-no-diagnostics
32

43
#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
54

65
// <rdar://problem/10962435>
7-
EVAL_EXPR(1, ((char*)-1LL) + 1 == 0 ? 1 : -1)
8-
EVAL_EXPR(2, ((char*)-1LL) + 1 < (char*) -1 ? 1 : -1)
6+
EVAL_EXPR(1, ((char*)-1LL) + 1 == 0 ? 1 : -1) // expected-warning {{folded}}
7+
EVAL_EXPR(2, ((char*)-1LL) + 1 < (char*) -1 ? 1 : -1) // expected-warning {{folded}}

clang/test/Sema/const-eval.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux %s -Wno-tautological-pointer-compare -Wno-pointer-to-int-cast
22

3-
#define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
3+
#define EVAL_EXPR(testno, expr) enum { test##testno = (expr) }; struct check_positive##testno { int a[test##testno]; };
44
int x;
55
EVAL_EXPR(1, (_Bool)&x)
66
EVAL_EXPR(2, (int)(1.0+(double)4))
@@ -14,12 +14,12 @@ EVAL_EXPR(8, (_Bool)"asdf")
1414
EVAL_EXPR(9, !!&x)
1515
EVAL_EXPR(10, ((void)1, 12))
1616
void g0(void);
17-
EVAL_EXPR(11, (g0(), 12)) // expected-error {{must have a constant size}}
17+
EVAL_EXPR(11, (g0(), 12)) // expected-error {{not an integer constant expression}}
1818
EVAL_EXPR(12, 1.0&&2.0)
19-
EVAL_EXPR(13, x || 3.0) // expected-error {{must have a constant size}}
19+
EVAL_EXPR(13, x || 3.0) // expected-error {{not an integer constant expression}}
2020

2121
unsigned int l_19 = 1;
22-
EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}}
22+
EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{not an integer constant expression}}
2323

2424
void f()
2525
{
@@ -36,7 +36,7 @@ int g17[(3?:1) - 2];
3636
EVAL_EXPR(18, ((int)((void*)10 + 10)) == 20 ? 1 : -1);
3737

3838
struct s {
39-
int a[(int)-1.0f]; // expected-error {{'a' declared as an array with a negative size}}
39+
int a[(int)-1.0f]; // expected-error {{array size is negative}}
4040
};
4141

4242
EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
@@ -47,9 +47,9 @@ EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);
4747

4848
EVAL_EXPR(22, (__real__ (2i+3)) == 3 ? 1 : -1);
4949

50-
int g23[(int)(1.0 / 1.0)] = { 1 };
51-
int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{excess elements in array initializer}}
52-
int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25);
50+
int g23[(int)(1.0 / 1.0)] = { 1 }; // expected-warning {{folded to constant array}}
51+
int g24[(int)(1.0 / 1.0)] = { 1 , 2 }; // expected-warning {{folded to constant array}} expected-warning {{excess elements in array initializer}}
52+
int g25[(int)(1.0 + 1.0)], g26 = sizeof(g25); // expected-warning {{folded to constant array}}
5353

5454
EVAL_EXPR(26, (_Complex double)0 ? -1 : 1)
5555
EVAL_EXPR(27, (_Complex int)0 ? -1 : 1)
@@ -116,17 +116,17 @@ EVAL_EXPR(42, __builtin_constant_p(pr11391.f = 1))
116116
// PR12043
117117
float varfloat;
118118
const float constfloat = 0;
119-
EVAL_EXPR(43, varfloat && constfloat) // expected-error {{must have a constant size}}
119+
EVAL_EXPR(43, varfloat && constfloat) // expected-error {{not an integer constant expression}}
120120

121121
// <rdar://problem/10962435>
122122
EVAL_EXPR(45, ((char*)-1) + 1 == 0 ? 1 : -1)
123123
EVAL_EXPR(46, ((char*)-1) + 1 < (char*) -1 ? 1 : -1)
124124
EVAL_EXPR(47, &x < &x + 1 ? 1 : -1)
125125
EVAL_EXPR(48, &x != &x - 1 ? 1 : -1)
126-
EVAL_EXPR(49, &x < &x - 100 ? 1 : -1) // expected-error {{must have a constant size}}
126+
EVAL_EXPR(49, &x < &x - 100 ? 1 : -1) // expected-error {{not an integer constant expression}}
127127

128128
extern struct Test50S Test50;
129-
EVAL_EXPR(50, &Test50 < (struct Test50S*)((unsigned long)&Test50 + 10)) // expected-error {{must have a constant size}}
129+
EVAL_EXPR(50, &Test50 < (struct Test50S*)((unsigned long)&Test50 + 10)) // expected-error {{not an integer constant expression}}
130130

131131
// <rdar://problem/11874571>
132132
EVAL_EXPR(51, 0 != (float)1e99)
@@ -136,7 +136,7 @@ void PR21945() { int i = (({}), 0l); }
136136

137137
void PR24622();
138138
struct PR24622 {} pr24622;
139-
EVAL_EXPR(52, &pr24622 == (void *)&PR24622); // expected-error {{must have a constant size}}
139+
EVAL_EXPR(52, &pr24622 == (void *)&PR24622); // expected-error {{not an integer constant expression}}
140140

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

clang/test/Sema/darwin-align-cast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clang_cc1 -fsyntax-only -Wno-pointer-to-int-cast -verify %s
2-
// expected-no-diagnostics
32
typedef long unsigned int __darwin_size_t;
43
typedef long __darwin_ssize_t;
54
typedef __darwin_size_t size_t;
@@ -18,6 +17,7 @@ i386/_param.h:#define __DARWIN_ALIGN(p) ((__darwin_size_t)((char *)(p)
1817

1918
ssize_t sendFileDescriptor(int fd, void *data, size_t nbytes, int sendfd) {
2019
union {
20+
// expected-warning@+1 {{folded to constant array}}
2121
char control[(((__darwin_size_t)((char *)(sizeof(struct cmsghdr)) + (sizeof(__darwin_size_t) - 1)) &~ (sizeof(__darwin_size_t) - 1)) + ((__darwin_size_t)((char *)(sizeof(int)) + (sizeof(__darwin_size_t) - 1)) &~ (sizeof(__darwin_size_t) - 1)))];
2222
} control_un;
2323
return 0;

0 commit comments

Comments
 (0)