-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Sema] Add check for bitfield assignments to integral types (#69049)
This change introduces the bitfield conversion check after fixes to the test case. The original submission unfortunately did not comprehend differences in architecture for the diagnostic messages, leading to unanticipated failures in the arm build bots. Original PR: #68276 Clang does not check for bitfield assignment widths, while gcc checks this. gcc produced a warning like so for it's -Wconversion flag: ``` $ gcc -Wconversion -c test.c test.c: In function 'foo': test.c:10:15: warning: conversion from 'int' to 'signed char:7' may change value [-Wconversion] 10 | vxx.bf = x; // no warning | ^ ``` This change simply adds this check for integral types under the -Wbitfield-conversion compiler option.
- Loading branch information
1 parent
410f413
commit 708808e
Showing
5 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// RUN: %clang_cc1 -Wconversion -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -Wbitfield-conversion -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -triple armebv7-unknown-linux -Wbitfield-conversion \ | ||
// RUN: -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -triple arm64-unknown-linux -Wbitfield-conversion \ | ||
// RUN: -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -triple arm-unknown-linux -Wbitfield-conversion \ | ||
// RUN: -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -triple aarch64-unknown-linux -Wbitfield-conversion \ | ||
// RUN: -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -triple mipsel-unknown-linux -Wbitfield-conversion \ | ||
// RUN: -fsyntax-only -verify %s | ||
// RUN: %clang_cc1 -triple mips64el-unknown-linux -Wbitfield-conversion \ | ||
// RUN: -fsyntax-only -verify %s | ||
|
||
typedef struct _xx { | ||
int bf:9; // expected-note 3{{declared here}} | ||
} xx, *pxx; | ||
|
||
xx vxx; | ||
|
||
void foo1(int x) { | ||
vxx.bf = x; // expected-warning{{conversion from 'int' (32 bits) to bit-field 'bf' (9 bits) may change value}} | ||
} | ||
void foo2(short x) { | ||
vxx.bf = x; // expected-warning{{conversion from 'short' (16 bits) to bit-field 'bf' (9 bits) may change value}} | ||
} | ||
void foo3(char x) { | ||
vxx.bf = x; // no warning expected | ||
} | ||
void foo4(short x) { | ||
vxx.bf = 0xff & x; // no warning expected | ||
} | ||
void foo5(short x) { | ||
vxx.bf = 0x1ff & x; // no warning expected | ||
} | ||
void foo6(short x) { | ||
vxx.bf = 0x3ff & x; // expected-warning{{conversion from 'int' (10 bits) to bit-field 'bf' (9 bits) may change value}} | ||
} | ||
int fee(void) { | ||
return 0; | ||
} |