https://gcc.gnu.org/g:479dab62b828f93d6be48241178dbf654bdd33e7

commit r15-2952-g479dab62b828f93d6be48241178dbf654bdd33e7
Author: Torbjörn SVENSSON <torbjorn.svens...@foss.st.com>
Date:   Fri Aug 16 14:43:41 2024 +0200

    testsuite: Verify -fshort-enums and -fno-short-enums in pr33738.C
    
    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.svens...@foss.st.com>

Diff:
---
 gcc/testsuite/g++.dg/warn/pr33738-2.C | 27 +++++++++++++++++++++++++++
 gcc/testsuite/g++.dg/warn/pr33738.C   |  3 ++-
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/warn/pr33738-2.C 
b/gcc/testsuite/g++.dg/warn/pr33738-2.C
new file mode 100644
index 00000000000..84bbdaeecc7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/pr33738-2.C
@@ -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;
+}
+
diff --git a/gcc/testsuite/g++.dg/warn/pr33738.C 
b/gcc/testsuite/g++.dg/warn/pr33738.C
index 73e98d5e083..d899f91c018 100644
--- a/gcc/testsuite/g++.dg/warn/pr33738.C
+++ b/gcc/testsuite/g++.dg/warn/pr33738.C
@@ -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 {

Reply via email to