Skip to content

Commit

Permalink
NFC: Pre-commit test: -Wpointer-sign with plain char to [un]signed char
Browse files Browse the repository at this point in the history
Add tests with bad message text for `-Wpointer-sign` and run them with
both signed and unsigned versions of plain `char`.
  • Loading branch information
hubert-reinterpretcast committed Jan 11, 2021
1 parent 7470017 commit f635bcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions clang/test/Sema/incompatible-sign.c
Original file line number Diff line number Diff line change
@@ -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 different 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 different sign}}
struct { signed char *p; } s = { &c }; // expected-warning {{converts between pointers to integer types with different sign}}
p = &c; // expected-warning {{converts between pointers to integer types with different sign}}
plainCharToSignedChar(&c); // expected-warning {{converts between pointers to integer types with different sign}}
return &c; // expected-warning {{converts between pointers to integer types with different 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 different sign}}
(void) (char *[]){ [42] = uc }; // expected-warning {{converts between pointers to integer types with different sign}}
p = uc; // expected-warning {{converts between pointers to integer types with different sign}}
unsignedCharToPlainChar(uc); // expected-warning {{converts between pointers to integer types with different sign}}
return uc; // expected-warning {{converts between pointers to integer types with different sign}}
}
14 changes: 14 additions & 0 deletions clang/test/Sema/incompatible-sign.cpp
Original file line number Diff line number Diff line change
@@ -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 different sign}}
}

void unsignedToPlain() {
extern unsigned char uc;
char *p;
p = &uc; // expected-error {{converts between pointers to integer types with different sign}}
}

0 comments on commit f635bcd

Please sign in to comment.