
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.
193 lines
3.8 KiB
Objective-C
193 lines
3.8 KiB
Objective-C
// RUN: %clang_cc1 -Wno-error=return-type -triple i686-apple-darwin9 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -o %t %s
|
|
// RUN: FileCheck < %t %s
|
|
//
|
|
// CHECK: @OBJC_METH_VAR_TYPE_{{.*}} = private unnamed_addr constant [16 x i8] c"v12@0:4[3[4@]]8\00"
|
|
|
|
@class Int1;
|
|
|
|
struct Innermost {
|
|
unsigned char a, b;
|
|
};
|
|
|
|
@interface Int1 {
|
|
signed char a, b;
|
|
struct Innermost *innermost;
|
|
}
|
|
@end
|
|
|
|
@implementation Int1
|
|
@end
|
|
|
|
@interface Base
|
|
{
|
|
struct objc_class *isa;
|
|
int full;
|
|
int full2: 32;
|
|
int _refs: 8;
|
|
int field2: 3;
|
|
unsigned f3: 8;
|
|
short cc;
|
|
unsigned g: 16;
|
|
int r2: 8;
|
|
int r3: 8;
|
|
int r4: 2;
|
|
int r5: 8;
|
|
char c;
|
|
}
|
|
@end
|
|
|
|
@interface Derived: Base
|
|
{
|
|
char d;
|
|
int _field3: 6;
|
|
}
|
|
@end
|
|
|
|
@implementation Base
|
|
@end
|
|
|
|
@implementation Derived
|
|
@end
|
|
|
|
@interface B1
|
|
{
|
|
struct objc_class *isa;
|
|
Int1 *sBase;
|
|
char c;
|
|
}
|
|
@end
|
|
|
|
@implementation B1
|
|
@end
|
|
|
|
@interface Test
|
|
{
|
|
int ivar;
|
|
__attribute__((objc_gc(weak))) SEL selector;
|
|
}
|
|
-(void) test3: (Test* [3] [4])b ;
|
|
- (SEL**) meth : (SEL) arg : (SEL*****) arg1 : (SEL*)arg2 : (SEL**) arg3;
|
|
@end
|
|
|
|
@implementation Test
|
|
-(void) test3: (Test* [3] [4])b {}
|
|
- (SEL**) meth : (SEL) arg : (SEL*****) arg1 : (SEL*)arg2 : (SEL**) arg3 {}
|
|
@end
|
|
|
|
struct S { int iS; };
|
|
|
|
@interface Object
|
|
{
|
|
Class isa;
|
|
}
|
|
@end
|
|
typedef Object MyObj;
|
|
|
|
int main(void)
|
|
{
|
|
const char *en = @encode(Derived);
|
|
const char *eb = @encode(B1);
|
|
const char *es = @encode(const struct S *);
|
|
const char *ec = @encode(const struct S);
|
|
const char *ee = @encode(MyObj *const);
|
|
}
|
|
|
|
// CHECK: @g0 ={{.*}} constant [15 x i8] c"{Innermost=CC}\00"
|
|
const char g0[] = @encode(struct Innermost);
|
|
|
|
// CHECK: @g1 ={{.*}} constant [38 x i8] c"{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}\00"
|
|
const char g1[] = @encode(Derived);
|
|
|
|
// CHECK: @g2 ={{.*}} constant [9 x i8] c"{B1=#@c}\00"
|
|
const char g2[] = @encode(B1);
|
|
|
|
// CHECK: @g3 ={{.*}} constant [8 x i8] c"r^{S=i}\00"
|
|
const char g3[] = @encode(const struct S *);
|
|
|
|
// CHECK: @g4 ={{.*}} constant [6 x i8] c"{S=i}\00"
|
|
const char g4[] = @encode(const struct S);
|
|
|
|
// CHECK: @g5 ={{.*}} constant [2 x i8] c"@\00"
|
|
const char g5[] = @encode(MyObj * const);
|
|
|
|
////
|
|
|
|
enum Enum1X { one, two, three, four };
|
|
|
|
@interface Base1X {
|
|
unsigned a: 2;
|
|
int b: 3;
|
|
enum Enum1X c: 4;
|
|
unsigned d: 5;
|
|
}
|
|
@end
|
|
|
|
@interface Derived1X: Base1X {
|
|
signed e: 5;
|
|
int f: 4;
|
|
enum Enum1X g: 3;
|
|
}
|
|
@end
|
|
|
|
@implementation Base1X @end
|
|
|
|
@implementation Derived1X @end
|
|
|
|
// CHECK: @g6 ={{.*}} constant [18 x i8] c"{Base1X=b2b3b4b5}\00"
|
|
const char g6[] = @encode(Base1X);
|
|
|
|
// CHECK: @g7 ={{.*}} constant [27 x i8] c"{Derived1X=b2b3b4b5b5b4b3}\00"
|
|
const char g7[] = @encode(Derived1X);
|
|
|
|
// CHECK: @g8 ={{.*}} constant [7 x i8] c"{s8=D}\00"
|
|
struct s8 {
|
|
long double x;
|
|
};
|
|
const char g8[] = @encode(struct s8);
|
|
|
|
// CHECK: @g9 ={{.*}} constant [11 x i8] c"{S9=i[0i]}\00"
|
|
struct S9 {
|
|
int x;
|
|
int flex[];
|
|
};
|
|
const char g9[] = @encode(struct S9);
|
|
|
|
struct f
|
|
{
|
|
int i;
|
|
struct{} g[4];
|
|
int tt;
|
|
};
|
|
|
|
// CHECK: @g10 ={{.*}} constant [14 x i8] c"{f=i[4{?=}]i}\00"
|
|
const char g10[] = @encode(struct f);
|
|
|
|
// CHECK: @g11 ={{.*}} constant [2 x i8] c"v\00"
|
|
const char g11[] = @encode(void);
|
|
|
|
// PR14628
|
|
// CHECK: @g12 ={{.*}} constant [3 x i8] c"Ai\00"
|
|
const char g12[] = @encode(_Atomic(int));
|
|
|
|
id test_id = 0;
|
|
Class test_class = 0;
|
|
const char g13[] = @encode(__typeof__(*test_class));
|
|
const char g14[] = @encode(__typeof__(*test_id));
|
|
// CHECK: constant [14 x i8] c"{objc_class=}\00"
|
|
// CHECK: constant [15 x i8] c"{objc_object=}\00"
|
|
|
|
// CHECK: @g15 ={{.*}} constant [2 x i8] c":\00"
|
|
const char g15[] = @encode(SEL);
|
|
|
|
typedef typeof(sizeof(int)) size_t;
|
|
size_t strlen(const char *s);
|
|
|
|
// CHECK-LABEL: @test_strlen(
|
|
// CHECK: %[[i:.*]] = alloca i32
|
|
// CHECK: %[[call:.*]] = call i32 @strlen
|
|
// CHECK: store i32 %[[call]], ptr %[[i]]
|
|
void test_strlen(void) {
|
|
const char array[] = @encode(int);
|
|
int i = strlen(array);
|
|
}
|