]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Verify -fshort-enums and -fno-short-enums in pr33738.C
authorTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Fri, 16 Aug 2024 12:43:41 +0000 (14:43 +0200)
committerTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Fri, 16 Aug 2024 14:50:24 +0000 (16:50 +0200)
For some targets, like Cortex-M on arm-none-eabi, the -fshort-enums is
enabled by default. For these targets, the test case fails as
sizeof(Alpha) < sizeof(int).
To make the test case behave identical for targets that does enable
-fshort-enums and those that does not, add -fno-short-enums in the test
case and verify that the warning is not emitted. Then also create a copy
and run the test with -fshort-enums and verify that the warning is
emitted.

Regtested on x86_64-pc-linux-gnu and arm-none-eabi.

gcc/testsuite/ChangeLog:

* g++.dg/warn/pr33738.C: Added -fno-short-enums.
* g++.dg/warn/pr33738-2.C: Duplicate g++.dg/warn/pr33738.C with
-fshort-enums and removed xfail.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
gcc/testsuite/g++.dg/warn/pr33738-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr33738.C

diff --git a/gcc/testsuite/g++.dg/warn/pr33738-2.C b/gcc/testsuite/g++.dg/warn/pr33738-2.C
new file mode 100644 (file)
index 0000000..84bbdae
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do run }
+// { dg-options "-O2 -Wtype-limits -fstrict-enums -fshort-enums" }
+extern void link_error (void);
+
+enum Alpha {
+ ZERO = 0, ONE, TWO, THREE
+};
+
+Alpha a2;
+
+int m1 = -1;
+int GetM1() {
+ return m1;
+}
+
+int main() {
+ a2 = static_cast<Alpha>(GetM1());
+ if (a2 == -1) {       // { dg-warning "always false due" } */
+    link_error ();
+ }
+ a2 = static_cast<Alpha>(GetM1());
+ if (-1 == a2) {       // { dg-warning "always false due" } */
+    link_error ();
+ }
+ return 0;
+}
+
index 73e98d5e083c4e419e6df0ec651a0bdc0704eb2e..d899f91c018194f0a619e84f9826daea51e0971a 100644 (file)
@@ -1,5 +1,6 @@
 // { dg-do run }
-// { dg-options "-O2 -Wtype-limits -fstrict-enums" }
+// { dg-prune-output "use of enum values across objects may fail" }
+// { dg-options "-O2 -Wtype-limits -fstrict-enums -fno-short-enums" }
 extern void link_error (void);
 
 enum Alpha {