llvm-project/clang/test/Sema/sign-conversion.c
Yaxun (Sam) Liu 8cda128c1e [clang]Fix warning for signed conversion on LP64
Currently clang emits warning with -Wconversion for the following code
on LP64 system e.g. x86_64-unknown-linux-gnu:

long foo(long x) {
  return 1LL<<x;
}
warning: implicit conversion changes signedness: 'long long' to 'long' [-Wsign-conversion]

return 1ll << x;
~~~~~~ ~~~~^~~~
This does not make sense since all operands are signed.

This patch fixes that to match -m32 and GCC behaviour.

Reviewed by: Fangrui Song

Differential Revision: https://reviews.llvm.org/D144011
2023-02-21 12:43:42 -05:00

15 lines
639 B
C

// RUN: %clang_cc1 -fsyntax-only -verify -Wsign-conversion %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify -Wsign-conversion %s
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsyntax-only -verify -Wsign-conversion %s
// PR9345: make a subgroup of -Wconversion for signedness changes
void test(int x) {
unsigned t0 = x; // expected-warning {{implicit conversion changes signedness}}
unsigned t1 = (t0 == 5 ? x : 0); // expected-warning {{operand of ? changes signedness}}
// Clang has special treatment for left shift of literal '1'.
// Make sure there is no diagnostics.
long t2 = 1LL << x;
}