[clang] f635bcd - NFC: Pre-commit test: -Wpointer-sign with plain char to [un]signed char
Hubert Tong via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 11 15:41:22 PST 2021
Author: Hubert Tong
Date: 2021-01-11T18:41:14-05:00
New Revision: f635bcd16105a0a01eefa2c69a71cd103dedaddd
URL: https://github.com/llvm/llvm-project/commit/f635bcd16105a0a01eefa2c69a71cd103dedaddd
DIFF: https://github.com/llvm/llvm-project/commit/f635bcd16105a0a01eefa2c69a71cd103dedaddd.diff
LOG: NFC: Pre-commit test: -Wpointer-sign with plain char to [un]signed char
Add tests with bad message text for `-Wpointer-sign` and run them with
both signed and unsigned versions of plain `char`.
Added:
clang/test/Sema/incompatible-sign.cpp
Modified:
clang/test/Sema/incompatible-sign.c
Removed:
################################################################################
diff --git a/clang/test/Sema/incompatible-sign.c b/clang/test/Sema/incompatible-sign.c
index 6249feb6b1e7..74e8b5dcc1fc 100644
--- a/clang/test/Sema/incompatible-sign.c
+++ b/clang/test/Sema/incompatible-sign.c
@@ -1,5 +1,23 @@
// RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fno-signed-char
int a(int* x); // expected-note{{passing argument to parameter 'x' here}}
int b(unsigned* y) { return a(y); } // expected-warning {{passing 'unsigned int *' to parameter of type 'int *' converts between pointers to integer types with
diff erent sign}}
+signed char *plainCharToSignedChar(signed char *arg) { // expected-note{{passing argument to parameter}}
+ extern char c;
+ signed char *p = &c; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ struct { signed char *p; } s = { &c }; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ p = &c; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ plainCharToSignedChar(&c); // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ return &c; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+}
+
+char *unsignedCharToPlainChar(char *arg) { // expected-note{{passing argument to parameter}}
+ extern unsigned char uc[];
+ char *p = uc; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ (void) (char *[]){ [42] = uc }; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ p = uc; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ unsignedCharToPlainChar(uc); // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+ return uc; // expected-warning {{converts between pointers to integer types with
diff erent sign}}
+}
diff --git a/clang/test/Sema/incompatible-sign.cpp b/clang/test/Sema/incompatible-sign.cpp
new file mode 100644
index 000000000000..ebe7585b81e0
--- /dev/null
+++ b/clang/test/Sema/incompatible-sign.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only -fno-signed-char
+
+void plainToSigned() {
+ extern char c;
+ signed char *p;
+ p = &c; // expected-error {{converts between pointers to integer types with
diff erent sign}}
+}
+
+void unsignedToPlain() {
+ extern unsigned char uc;
+ char *p;
+ p = &uc; // expected-error {{converts between pointers to integer types with
diff erent sign}}
+}
More information about the cfe-commits
mailing list