Skip to content

Commit 1a42255

Browse files
committed
[C2y] Modify diagnostics for complex increment/decrement
Clang implemented WG14 N3259 as an extension, now it's a feature of C2y.
1 parent 9a7248a commit 1a42255

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7664,8 +7664,12 @@ def ext_gnu_ptr_func_arith : Extension<
76647664
InGroup<GNUPointerArith>;
76657665
def err_readonly_message_assignment : Error<
76667666
"assigning to 'readonly' return result of an Objective-C message not allowed">;
7667-
def ext_increment_complex : Extension<
7668-
"'%select{--|++}0' on an object of complex type is a Clang extension">;
7667+
def ext_c2y_increment_complex : Extension<
7668+
"'%select{--|++}0' on an object of complex type is a C2y extension">,
7669+
InGroup<C2y>;
7670+
def warn_c2y_compat_increment_complex : Warning<
7671+
"'%select{--|++}0' on an object of complex type is incompatible with C "
7672+
"standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore;
76697673
def ext_integer_complement_complex : Extension<
76707674
"ISO C does not support '~' for complex conjugation of %0">;
76717675
def err_nosetter_property_assignment : Error<

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13764,8 +13764,9 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op,
1376413764
return QualType();
1376513765
} else if (ResType->isAnyComplexType()) {
1376613766
// C99 does not support ++/-- on complex types, we allow as an extension.
13767-
S.Diag(OpLoc, diag::ext_increment_complex)
13768-
<< IsInc << Op->getSourceRange();
13767+
S.Diag(OpLoc, S.getLangOpts().C2y ? diag::warn_c2y_compat_increment_complex
13768+
: diag::ext_c2y_increment_complex)
13769+
<< IsInc << Op->getSourceRange();
1376913770
} else if (ResType->isPlaceholderType()) {
1377013771
ExprResult PR = S.CheckPlaceholderExpr(Op);
1377113772
if (PR.isInvalid()) return QualType();

clang/test/C/C2y/n3259.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %clang_cc1 -std=c2y -Wall -pedantic -Wno-unused -Wpre-c2y-compat -verify=pre-c2y %s -emit-llvm -o - | FileCheck %s
2+
// RUN: %clang_cc1 -std=c23 -Wall -pedantic -Wno-unused %s -verify -emit-llvm -o - | FileCheck %s
3+
4+
/* WG14 N3259: Yes
5+
* Support ++ and -- on complex values
6+
*/
7+
8+
// CHECK-LABEL: define {{.*}} void @test()
9+
void test() {
10+
// CHECK: %[[F:.+]] = alloca { float, float }
11+
// CHECK: store float 1
12+
// CHECK: store float 0
13+
_Complex float f = __builtin_complex(1.0f, 0.0f);
14+
15+
// CHECK: %[[F_REALP1:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
16+
// CHECK-NEXT: %[[F_REAL:.+]] = load float, ptr %[[F_REALP1]]
17+
// CHECK-NEXT: %[[F_IMAGP2:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
18+
// CHECK-NEXT: %[[F_IMAG:.+]] = load float, ptr %[[F_IMAGP2]]
19+
// CHECK-NEXT: %[[INC:.+]] = fadd float %[[F_REAL]], 1.000000e+00
20+
// CHECK-NEXT: %[[F_REALP3:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
21+
// CHECK-NEXT: %[[F_IMAGP4:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
22+
// CHECK-NEXT: store float %[[INC]], ptr %[[F_REALP3]]
23+
// CHECK-NEXT: store float %[[F_IMAG]], ptr %[[F_IMAGP4]]
24+
f++; /* expected-warning {{'++' on an object of complex type is a C2y extension}}
25+
pre-c2y-warning {{'++' on an object of complex type is incompatible with C standards before C2y}}
26+
*/
27+
28+
// CHECK: %[[F_REALP5:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
29+
// CHECK-NEXT: %[[F_REAL6:.+]] = load float, ptr %[[F_REALP5]]
30+
// CHECK-NEXT: %[[F_IMAGP7:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
31+
// CHECK-NEXT: %[[F_IMAG8:.+]] = load float, ptr %[[F_IMAGP7]]
32+
// CHECK-NEXT: %[[INC9:.+]] = fadd float %[[F_REAL6]], 1.000000e+00
33+
// CHECK-NEXT: %[[F_REALP10:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
34+
// CHECK-NEXT: %[[F_IMAGP11:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
35+
// CHECK-NEXT: store float %[[INC9]], ptr %[[F_REALP10]]
36+
// CHECK-NEXT: store float %[[F_IMAG8]], ptr %[[F_IMAGP11]]
37+
++f; /* expected-warning {{'++' on an object of complex type is a C2y extension}}
38+
pre-c2y-warning {{'++' on an object of complex type is incompatible with C standards before C2y}}
39+
*/
40+
41+
// CHECK: %[[F_REALP12:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
42+
// CHECK-NEXT: %[[F_REAL13:.+]] = load float, ptr %[[F_REALP12]]
43+
// CHECK-NEXT: %[[F_IMAGP14:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
44+
// CHECK-NEXT: %[[F_IMAG15:.+]] = load float, ptr %[[F_IMAGP14]]
45+
// CHECK-NEXT: %[[DEC:.+]] = fadd float %[[F_REAL13]], -1.000000e+00
46+
// CHECK-NEXT: %[[F_REALP16:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
47+
// CHECK-NEXT: %[[F_IMAGP17:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
48+
// CHECK-NEXT: store float %[[DEC]], ptr %[[F_REALP16]]
49+
// CHECK-NEXT: store float %[[F_IMAG15]], ptr %[[F_IMAGP17]]
50+
f--; /* expected-warning {{'--' on an object of complex type is a C2y extension}}
51+
pre-c2y-warning {{'--' on an object of complex type is incompatible with C standards before C2y}}
52+
*/
53+
54+
// CHECK: %[[F_REALP18:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
55+
// CHECK-NEXT: %[[F_REAL19:.+]] = load float, ptr %[[F_REALP18]]
56+
// CHECK-NEXT: %[[F_IMAGP20:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
57+
// CHECK-NEXT: %[[F_IMAG21:.+]] = load float, ptr %[[F_IMAGP20]]
58+
// CHECK-NEXT: %[[DEC22:.+]] = fadd float %[[F_REAL19]], -1.000000e+00
59+
// CHECK-NEXT: %[[F_REALP23:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
60+
// CHECK-NEXT: %[[F_IMAGP24:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
61+
// CHECK-NEXT: store float %[[DEC22]], ptr %[[F_REALP23]]
62+
// CHECK-NEXT: store float %[[F_IMAG21]], ptr %[[F_IMAGP24]]
63+
--f; /* expected-warning {{'--' on an object of complex type is a C2y extension}}
64+
pre-c2y-warning {{'--' on an object of complex type is incompatible with C standards before C2y}}
65+
*/
66+
}

0 commit comments

Comments
 (0)