[clang] 1e26a25 - [C2y] Modify diagnostics for complex increment/decrement
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 06:29:54 PDT 2024
Author: Aaron Ballman
Date: 2024-07-02T09:29:23-04:00
New Revision: 1e26a251a36b0479c7aca21e2d65d9877c0691ce
URL: https://github.com/llvm/llvm-project/commit/1e26a251a36b0479c7aca21e2d65d9877c0691ce
DIFF: https://github.com/llvm/llvm-project/commit/1e26a251a36b0479c7aca21e2d65d9877c0691ce.diff
LOG: [C2y] Modify diagnostics for complex increment/decrement
Clang implemented WG14 N3259 as an extension, now it's a feature of C2y.
Added:
clang/test/C/C2y/n3259.c
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaExpr.cpp
clang/test/C/C99/n809.c
clang/test/Misc/warning-flags.c
clang/test/Sema/complex-inc-dec.c
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c852f1893fe14..3d3e98c7b751b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7664,8 +7664,12 @@ def ext_gnu_ptr_func_arith : Extension<
InGroup<GNUPointerArith>;
def err_readonly_message_assignment : Error<
"assigning to 'readonly' return result of an Objective-C message not allowed">;
-def ext_increment_complex : Extension<
- "'%select{--|++}0' on an object of complex type is a Clang extension">;
+def ext_c2y_increment_complex : Extension<
+ "'%select{--|++}0' on an object of complex type is a C2y extension">,
+ InGroup<C2y>;
+def warn_c2y_compat_increment_complex : Warning<
+ "'%select{--|++}0' on an object of complex type is incompatible with C "
+ "standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore;
def ext_integer_complement_complex : Extension<
"ISO C does not support '~' for complex conjugation of %0">;
def err_nosetter_property_assignment : Error<
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index cc811a40185ce..1437fa08d2e7a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -13764,8 +13764,9 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op,
return QualType();
} else if (ResType->isAnyComplexType()) {
// C99 does not support ++/-- on complex types, we allow as an extension.
- S.Diag(OpLoc, diag::ext_increment_complex)
- << IsInc << Op->getSourceRange();
+ S.Diag(OpLoc, S.getLangOpts().C2y ? diag::warn_c2y_compat_increment_complex
+ : diag::ext_c2y_increment_complex)
+ << IsInc << Op->getSourceRange();
} else if (ResType->isPlaceholderType()) {
ExprResult PR = S.CheckPlaceholderExpr(Op);
if (PR.isInvalid()) return QualType();
diff --git a/clang/test/C/C2y/n3259.c b/clang/test/C/C2y/n3259.c
new file mode 100644
index 0000000000000..84118a76660c9
--- /dev/null
+++ b/clang/test/C/C2y/n3259.c
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c2y -Wall -pedantic -Wno-unused -Wpre-c2y-compat -verify=pre-c2y %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c23 -Wall -pedantic -Wno-unused %s -verify -emit-llvm -o - | FileCheck %s
+
+/* WG14 N3259: Yes
+ * Support ++ and -- on complex values
+ */
+
+// CHECK-LABEL: define {{.*}} void @test()
+void test() {
+ // CHECK: %[[F:.+]] = alloca { float, float }
+ // CHECK: store float 1
+ // CHECK: store float 0
+ _Complex float f = __builtin_complex(1.0f, 0.0f);
+
+ // CHECK: %[[F_REALP1:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_REAL:.+]] = load float, ptr %[[F_REALP1]]
+ // CHECK-NEXT: %[[F_IMAGP2:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: %[[F_IMAG:.+]] = load float, ptr %[[F_IMAGP2]]
+ // CHECK-NEXT: %[[INC:.+]] = fadd float %[[F_REAL]], 1.000000e+00
+ // CHECK-NEXT: %[[F_REALP3:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_IMAGP4:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: store float %[[INC]], ptr %[[F_REALP3]]
+ // CHECK-NEXT: store float %[[F_IMAG]], ptr %[[F_IMAGP4]]
+ f++; /* expected-warning {{'++' on an object of complex type is a C2y extension}}
+ pre-c2y-warning {{'++' on an object of complex type is incompatible with C standards before C2y}}
+ */
+
+ // CHECK: %[[F_REALP5:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_REAL6:.+]] = load float, ptr %[[F_REALP5]]
+ // CHECK-NEXT: %[[F_IMAGP7:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: %[[F_IMAG8:.+]] = load float, ptr %[[F_IMAGP7]]
+ // CHECK-NEXT: %[[INC9:.+]] = fadd float %[[F_REAL6]], 1.000000e+00
+ // CHECK-NEXT: %[[F_REALP10:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_IMAGP11:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: store float %[[INC9]], ptr %[[F_REALP10]]
+ // CHECK-NEXT: store float %[[F_IMAG8]], ptr %[[F_IMAGP11]]
+ ++f; /* expected-warning {{'++' on an object of complex type is a C2y extension}}
+ pre-c2y-warning {{'++' on an object of complex type is incompatible with C standards before C2y}}
+ */
+
+ // CHECK: %[[F_REALP12:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_REAL13:.+]] = load float, ptr %[[F_REALP12]]
+ // CHECK-NEXT: %[[F_IMAGP14:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: %[[F_IMAG15:.+]] = load float, ptr %[[F_IMAGP14]]
+ // CHECK-NEXT: %[[DEC:.+]] = fadd float %[[F_REAL13]], -1.000000e+00
+ // CHECK-NEXT: %[[F_REALP16:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_IMAGP17:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: store float %[[DEC]], ptr %[[F_REALP16]]
+ // CHECK-NEXT: store float %[[F_IMAG15]], ptr %[[F_IMAGP17]]
+ f--; /* expected-warning {{'--' on an object of complex type is a C2y extension}}
+ pre-c2y-warning {{'--' on an object of complex type is incompatible with C standards before C2y}}
+ */
+
+ // CHECK: %[[F_REALP18:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_REAL19:.+]] = load float, ptr %[[F_REALP18]]
+ // CHECK-NEXT: %[[F_IMAGP20:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: %[[F_IMAG21:.+]] = load float, ptr %[[F_IMAGP20]]
+ // CHECK-NEXT: %[[DEC22:.+]] = fadd float %[[F_REAL19]], -1.000000e+00
+ // CHECK-NEXT: %[[F_REALP23:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 0
+ // CHECK-NEXT: %[[F_IMAGP24:.+]] = getelementptr inbounds { float, float }, ptr %[[F]], i32 0, i32 1
+ // CHECK-NEXT: store float %[[DEC22]], ptr %[[F_REALP23]]
+ // CHECK-NEXT: store float %[[F_IMAG21]], ptr %[[F_IMAGP24]]
+ --f; /* expected-warning {{'--' on an object of complex type is a C2y extension}}
+ pre-c2y-warning {{'--' on an object of complex type is incompatible with C standards before C2y}}
+ */
+}
diff --git a/clang/test/C/C99/n809.c b/clang/test/C/C99/n809.c
index 7297443a777cc..48a72cccb64e6 100644
--- a/clang/test/C/C99/n809.c
+++ b/clang/test/C/C99/n809.c
@@ -108,11 +108,11 @@ void func(void) {
// a real type; Clang supports this as an extension on complex types as well.
_Complex float cf = 0.0f;
- cf++; // expected-warning {{'++' on an object of complex type is a Clang extension}}
- ++cf; // expected-warning {{'++' on an object of complex type is a Clang extension}}
+ cf++; // expected-warning {{'++' on an object of complex type is a C2y extension}}
+ ++cf; // expected-warning {{'++' on an object of complex type is a C2y extension}}
- cf--; // expected-warning {{'--' on an object of complex type is a Clang extension}}
- --cf; // expected-warning {{'--' on an object of complex type is a Clang extension}}
+ cf--; // expected-warning {{'--' on an object of complex type is a C2y extension}}
+ --cf; // expected-warning {{'--' on an object of complex type is a C2y extension}}
// However, unary + and - are fine, as is += 1.
(void)-cf;
diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c
index ae14720959a0e..cdbe1e95cba96 100644
--- a/clang/test/Misc/warning-flags.c
+++ b/clang/test/Misc/warning-flags.c
@@ -88,4 +88,4 @@ CHECK-NEXT: warn_weak_import
The list of warnings in -Wpedantic should NEVER grow.
-CHECK: Number in -Wpedantic (not covered by other -W flags): 26
+CHECK: Number in -Wpedantic (not covered by other -W flags): 25
diff --git a/clang/test/Sema/complex-inc-dec.c b/clang/test/Sema/complex-inc-dec.c
index ebc23c36f40c8..4c780da9bca4c 100644
--- a/clang/test/Sema/complex-inc-dec.c
+++ b/clang/test/Sema/complex-inc-dec.c
@@ -5,20 +5,20 @@ void func(void) {
_Complex double cd;
_Complex long double cld;
- ++cf; // expected-warning {{'++' on an object of complex type is a Clang extension}}
- ++cd; // expected-warning {{'++' on an object of complex type is a Clang extension}}
- ++cld; // expected-warning {{'++' on an object of complex type is a Clang extension}}
+ ++cf; // expected-warning {{'++' on an object of complex type is a C2y extension}}
+ ++cd; // expected-warning {{'++' on an object of complex type is a C2y extension}}
+ ++cld; // expected-warning {{'++' on an object of complex type is a C2y extension}}
- --cf; // expected-warning {{'--' on an object of complex type is a Clang extension}}
- --cd; // expected-warning {{'--' on an object of complex type is a Clang extension}}
- --cld; // expected-warning {{'--' on an object of complex type is a Clang extension}}
+ --cf; // expected-warning {{'--' on an object of complex type is a C2y extension}}
+ --cd; // expected-warning {{'--' on an object of complex type is a C2y extension}}
+ --cld; // expected-warning {{'--' on an object of complex type is a C2y extension}}
- cf++; // expected-warning {{'++' on an object of complex type is a Clang extension}}
- cd++; // expected-warning {{'++' on an object of complex type is a Clang extension}}
- cld++; // expected-warning {{'++' on an object of complex type is a Clang extension}}
+ cf++; // expected-warning {{'++' on an object of complex type is a C2y extension}}
+ cd++; // expected-warning {{'++' on an object of complex type is a C2y extension}}
+ cld++; // expected-warning {{'++' on an object of complex type is a C2y extension}}
- cf--; // expected-warning {{'--' on an object of complex type is a Clang extension}}
- cd--; // expected-warning {{'--' on an object of complex type is a Clang extension}}
- cld--; // expected-warning {{'--' on an object of complex type is a Clang extension}}
+ cf--; // expected-warning {{'--' on an object of complex type is a C2y extension}}
+ cd--; // expected-warning {{'--' on an object of complex type is a C2y extension}}
+ cld--; // expected-warning {{'--' on an object of complex type is a C2y extension}}
}
More information about the cfe-commits
mailing list