https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/130339
>From bed2cb009ae2e560aa00f86b90c57d82f97bb435 Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Fri, 7 Mar 2025 22:10:24 +0200 Subject: [PATCH 1/2] [Clang] add additional tests for -Wshift-bool --- clang/test/Sema/shift-bool.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/test/Sema/shift-bool.cpp b/clang/test/Sema/shift-bool.cpp index a17a0e0ad9e7d..efaca65aacaed 100644 --- a/clang/test/Sema/shift-bool.cpp +++ b/clang/test/Sema/shift-bool.cpp @@ -3,6 +3,7 @@ void t() { int x = 10; bool y = true; + int z = 1; bool a = y << x; bool b = y >> x; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}} @@ -22,4 +23,6 @@ void t() { if ((y << 1) != 0) { } if ((y >> 1) != 0) { } // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}} + + bool k = (x < z) >> 1; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}} } >From 9be7657ef45482a84c571b6b3f15be833841467a Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Tue, 11 Mar 2025 17:15:52 +0200 Subject: [PATCH 2/2] add c test --- clang/test/Sema/shift-bool.c | 24 ++++++++++++++++++++++++ clang/test/Sema/shift-bool.cpp | 3 --- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 clang/test/Sema/shift-bool.c diff --git a/clang/test/Sema/shift-bool.c b/clang/test/Sema/shift-bool.c new file mode 100644 index 0000000000000..589ba49fa2bba --- /dev/null +++ b/clang/test/Sema/shift-bool.c @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -Wshift-bool -verify %s + +void t() { + int x = 10; + int y = 1; + + int a = y << x; + int b = y >> x; + + int c = 0 << x; + int d = 0 >> x; + + int e = y << 1; + int f = y >> 1; + + int g = y << -1; // expected-warning {{shift count is negative}} + int h = y >> -1; // expected-warning {{shift count is negative}} + + int i = y << 0; + int j = y >> 0; + + if ((y << 1) != 0) { } + if ((y >> 1) != 0) { } +} diff --git a/clang/test/Sema/shift-bool.cpp b/clang/test/Sema/shift-bool.cpp index efaca65aacaed..a17a0e0ad9e7d 100644 --- a/clang/test/Sema/shift-bool.cpp +++ b/clang/test/Sema/shift-bool.cpp @@ -3,7 +3,6 @@ void t() { int x = 10; bool y = true; - int z = 1; bool a = y << x; bool b = y >> x; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}} @@ -23,6 +22,4 @@ void t() { if ((y << 1) != 0) { } if ((y >> 1) != 0) { } // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}} - - bool k = (x < z) >> 1; // expected-warning {{right shifting a 'bool' implicitly converts it to 'int'}} } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits