mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 14:06:06 +00:00

In preparation of making `-Wreturn-type` default to an error (as there is virtually no situation where you’d *want* to fall off the end of a function that is supposed to return a value), this patch fixes tests that have relied on this being only a warning, of which there seem to be 3 kinds: 1. Tests which for no apparent reason have a function that triggers the warning. I suspect that a lot of these were on accident (or from before the warning was introduced), since a lot of people will open issues w/ their problematic code in the `main` function (which is the one case where you don’t need to return from a non-void function, after all...), which someone will then copy, possibly into a namespace, possibly renaming it, the end result of that being that you end up w/ something that definitely is not `main` anymore, but which still is declared as returning `int`, and which still has no return statement (another reason why I think this might apply to a lot of these is because usually the actual return type of such problematic functions is quite literally `int`). A lot of these are really old tests that don’t use `-verify`, which is why no-one noticed or had to care about the extra warning that was already being emitted by them until now. 2. Tests which test either `-Wreturn-type`, `[[noreturn]]`, or what codegen and sanitisers do whenever you do fall off the end of a function. 3. Tests where I struggle to figure out what is even being tested (usually because they’re Objective-C tests, and I don’t know Objective-C), whether falling off the end of a function matters in the first place, and tests where actually spelling out an expression to return would be rather cumbersome (e.g. matrix types currently don’t support list initialisation, so I can’t write e.g. `return {}`). For tests that fall into categories 2 and 3, I just added `-Wno-error=return-type` to the `RUN` lines and called it a day. This was especially necessary for the former since `-Wreturn-type` is an analysis-based warning, meaning that it is currently impossible to test for more than one occurrence of it in the same compilation if it defaults to an error since the analysis pass is skipped for subsequent functions as soon as an error is emitted. I’ve also added `-Werror=return-type` to a few tests that I had already updated as this patch was previously already making the warning an error by default, but we’ve decided to split that into two patches instead.
126 lines
3.3 KiB
C
126 lines
3.3 KiB
C
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s
|
|
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -fexperimental-new-constant-interpreter < %s| FileCheck %s
|
|
|
|
typedef __WCHAR_TYPE__ wchar_t;
|
|
typedef __SIZE_TYPE__ size_t;
|
|
|
|
void *memcpy(void *, void const *, size_t);
|
|
void *memccpy(void *, void const *, int, size_t);
|
|
|
|
// CHECK: @test1
|
|
// CHECK: call void @llvm.memset.p0.i32
|
|
// CHECK: call void @llvm.memset.p0.i32
|
|
// CHECK: call void @llvm.memcpy.p0.p0.i32
|
|
// CHECK: call void @llvm.memmove.p0.p0.i32
|
|
// CHECK-NOT: __builtin
|
|
// CHECK: ret
|
|
int test1(int argc, char **argv) {
|
|
unsigned char a = 0x11223344;
|
|
unsigned char b = 0x11223344;
|
|
__builtin_bzero(&a, sizeof(a));
|
|
__builtin_memset(&a, 0, sizeof(a));
|
|
__builtin_memcpy(&a, &b, sizeof(a));
|
|
__builtin_memmove(&a, &b, sizeof(a));
|
|
return 0;
|
|
}
|
|
|
|
// CHECK: @test2
|
|
// CHECK: call void @llvm.memcpy.p0.p0.i32
|
|
char* test2(char* a, char* b) {
|
|
return __builtin_memcpy(a, b, 4);
|
|
}
|
|
|
|
// CHECK: @test3
|
|
// CHECK: call void @llvm.memset
|
|
void test3(char *P) {
|
|
__builtin___memset_chk(P, 42, 128, 128);
|
|
}
|
|
|
|
// CHECK: @test4
|
|
// CHECK: call void @llvm.memcpy
|
|
void test4(char *P, char *Q) {
|
|
__builtin___memcpy_chk(P, Q, 128, 128);
|
|
}
|
|
|
|
// CHECK: @test5
|
|
// CHECK: call void @llvm.memmove
|
|
void test5(char *P, char *Q) {
|
|
__builtin___memmove_chk(P, Q, 128, 128);
|
|
}
|
|
|
|
// CHECK: @test6
|
|
// CHECK: call void @llvm.memcpy
|
|
int test6(char *X) {
|
|
return __builtin___memcpy_chk(X, X, 42, 42) != 0;
|
|
}
|
|
|
|
// CHECK: @test7
|
|
// PR12094
|
|
void test7(int *p) {
|
|
struct snd_pcm_hw_params_t* hwparams; // incomplete type.
|
|
|
|
// CHECK: call void @llvm.memset{{.*}} align 4 {{.*}}256, i1 false)
|
|
__builtin_memset(p, 0, 256); // Should be alignment = 4
|
|
|
|
// CHECK: call void @llvm.memset{{.*}} align 1 {{.*}}256, i1 false)
|
|
__builtin_memset((char*)p, 0, 256); // Should be alignment = 1
|
|
|
|
__builtin_memset(hwparams, 0, 256); // No crash alignment = 1
|
|
// CHECK: call void @llvm.memset{{.*}} align 1{{.*}}256, i1 false)
|
|
}
|
|
|
|
// Make sure we don't over-estimate the alignment of fields of
|
|
// packed structs.
|
|
struct PS {
|
|
int modes[4];
|
|
} __attribute__((packed));
|
|
struct PS ps;
|
|
void test8(int *arg) {
|
|
// CHECK: @test8
|
|
// CHECK: call void @llvm.memcpy{{.*}} align 4 {{.*}} align 1 {{.*}} 16, i1 false)
|
|
__builtin_memcpy(arg, ps.modes, sizeof(struct PS));
|
|
}
|
|
|
|
__attribute((aligned(16))) int x[4], y[4];
|
|
void test9(void) {
|
|
// CHECK: @test9
|
|
// CHECK: call void @llvm.memcpy{{.*}} align 16 {{.*}} align 16 {{.*}} 16, i1 false)
|
|
__builtin_memcpy(x, y, sizeof(y));
|
|
}
|
|
|
|
wchar_t dest;
|
|
wchar_t src;
|
|
|
|
// CHECK-LABEL: @test10
|
|
// FIXME: Consider lowering these to llvm.memcpy / llvm.memmove.
|
|
void test10(void) {
|
|
// CHECK: call ptr @wmemcpy(ptr noundef @dest, ptr noundef @src, i32 noundef 4)
|
|
__builtin_wmemcpy(&dest, &src, 4);
|
|
|
|
// CHECK: call ptr @wmemmove(ptr noundef @dest, ptr noundef @src, i32 noundef 4)
|
|
__builtin_wmemmove(&dest, &src, 4);
|
|
}
|
|
|
|
// CHECK-LABEL: @test11
|
|
void test11(void) {
|
|
typedef struct { int a; } b;
|
|
int d;
|
|
b e;
|
|
// CHECK: call void @llvm.memcpy{{.*}}(
|
|
memcpy(&d, (char *)&e.a, sizeof(e));
|
|
}
|
|
|
|
// CHECK-LABEL: @test12
|
|
extern char dest_array[];
|
|
extern char src_array[];
|
|
void test12(void) {
|
|
// CHECK: call void @llvm.memcpy{{.*}}(
|
|
memcpy(&dest_array, &dest_array, 2);
|
|
}
|
|
|
|
// CHECK-LABEL: @test13
|
|
void test13(char *d, char *s, int c, size_t n) {
|
|
// CHECK: call ptr @memccpy
|
|
memccpy(d, s, c, n);
|
|
}
|