Skip to content

Commit 12f78e7

Browse files
authored
[Clang] [NFC] Fix unintended -Wreturn-type warnings everywhere in the test suite (#123464)
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.
1 parent a5fb2bb commit 12f78e7

File tree

147 files changed

+271
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+271
-211
lines changed

clang/test/ARCMT/autoreleases.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ id test2(A* val) {
6969
return val;
7070
}
7171

72-
id test3(void) {
72+
void test3(void) {
7373
id a = [[A alloc] init];
7474
[a autorelease];
7575
}

clang/test/ARCMT/autoreleases.m.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ id test2(A* val) {
6464
return val;
6565
}
6666

67-
id test3(void) {
67+
void test3(void) {
6868
id a = [[A alloc] init];
6969
}

clang/test/ARCMT/retains.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ @implementation Foo
2121

2222
@synthesize bar;
2323

24-
-(id)something {}
24+
-(id)something { return (id)0; }
2525

2626
-(id)test:(id)obj {
2727
id x = self.bar;

clang/test/ARCMT/retains.m.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ id IhaveSideEffect(void);
2121

2222
@synthesize bar;
2323

24-
-(id)something {}
24+
-(id)something { return (id)0; }
2525

2626
-(id)test:(id)obj {
2727
id x = self.bar;

clang/test/AST/ast-dump-cxx2b-deducing-this.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ struct S {
55
int f(this S&);
66
};
77

8-
int main() {
8+
void main() {
99
S s;
1010
int x = s.f();
1111
// CHECK: CallExpr 0x{{[^ ]*}} <col:11, col:15> 'int

clang/test/AST/ast-dump-special-member-functions.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,25 +253,25 @@ struct TrivialCopyAssignment {
253253
struct NontrivialCopyAssignment {
254254
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct NontrivialCopyAssignment definition
255255
// CHECK: CopyAssignment {{.*}}non_trivial{{.*}}
256-
NontrivialCopyAssignment& operator=(const NontrivialCopyAssignment&) {}
256+
NontrivialCopyAssignment& operator=(const NontrivialCopyAssignment&) { return *this; }
257257
};
258258

259259
struct CopyAssignmentHasConstParam {
260260
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct CopyAssignmentHasConstParam definition
261261
// CHECK: CopyAssignment {{.*}}has_const_param{{.*}}
262-
CopyAssignmentHasConstParam& operator=(const CopyAssignmentHasConstParam&) {}
262+
CopyAssignmentHasConstParam& operator=(const CopyAssignmentHasConstParam&) { return *this; }
263263
};
264264

265265
struct CopyAssignmentDoesNotHaveConstParam {
266266
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct CopyAssignmentDoesNotHaveConstParam definition
267267
// CHECK-NOT: CopyAssignment {{.*}} has_const_param{{.*}}
268-
CopyAssignmentDoesNotHaveConstParam& operator=(CopyAssignmentDoesNotHaveConstParam&) {}
268+
CopyAssignmentDoesNotHaveConstParam& operator=(CopyAssignmentDoesNotHaveConstParam&) { return *this; }
269269
};
270270

271271
struct UserDeclaredCopyAssignment {
272272
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct UserDeclaredCopyAssignment definition
273273
// CHECK: CopyAssignment {{.*}}user_declared{{.*}}
274-
UserDeclaredCopyAssignment& operator=(const UserDeclaredCopyAssignment&) {}
274+
UserDeclaredCopyAssignment& operator=(const UserDeclaredCopyAssignment&) { return *this; }
275275
};
276276

277277
struct NonUserDeclaredCopyAssignment {
@@ -288,7 +288,7 @@ struct NeedsImplicitCopyAssignment {
288288
struct DoesNotNeedImplicitCopyAssignment {
289289
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct DoesNotNeedImplicitCopyAssignment definition
290290
// CHECK-NOT: CopyAssignment {{.*}}needs_implicit{{.*}}
291-
DoesNotNeedImplicitCopyAssignment& operator=(const DoesNotNeedImplicitCopyAssignment&) {}
291+
DoesNotNeedImplicitCopyAssignment& operator=(const DoesNotNeedImplicitCopyAssignment&) { return *this; }
292292
};
293293

294294
struct DeclaresCopyAssignment {
@@ -352,13 +352,13 @@ struct TrivialMoveAssignment {
352352
struct NontrivialMoveAssignment {
353353
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct NontrivialMoveAssignment definition
354354
// CHECK: MoveAssignment {{.*}}non_trivial{{.*}}
355-
NontrivialMoveAssignment& operator=(NontrivialMoveAssignment&&) {}
355+
NontrivialMoveAssignment& operator=(NontrivialMoveAssignment&&) { return *this; }
356356
};
357357

358358
struct UserDeclaredMoveAssignment {
359359
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct UserDeclaredMoveAssignment definition
360360
// CHECK: MoveAssignment {{.*}}user_declared{{.*}}
361-
UserDeclaredMoveAssignment& operator=(UserDeclaredMoveAssignment&&) {}
361+
UserDeclaredMoveAssignment& operator=(UserDeclaredMoveAssignment&&) { return *this; }
362362
};
363363

364364
struct NonUserDeclaredMoveAssignment {
@@ -375,7 +375,7 @@ struct NeedsImplicitMoveAssignment {
375375
struct DoesNotNeedImplicitMoveAssignment {
376376
// CHECK: CXXRecordDecl 0x{{[^ ]*}} <line:[[@LINE-1]]:1, line:[[@LINE+3]]:1> line:[[@LINE-1]]:8 struct DoesNotNeedImplicitMoveAssignment definition
377377
// CHECK-NOT: MoveAssignment {{.*}}needs_implicit{{.*}}
378-
DoesNotNeedImplicitMoveAssignment& operator=(DoesNotNeedImplicitMoveAssignment&&) {}
378+
DoesNotNeedImplicitMoveAssignment& operator=(DoesNotNeedImplicitMoveAssignment&&) { return *this; }
379379
};
380380

381381
struct MoveAssignmentNeedsOverloadResolution : virtual DeletedDestructor {

clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6151,7 +6151,7 @@
61516151
<key>type</key><string>Argument with &apos;nonnull&apos; attribute passed null</string>
61526152
<key>check_name</key><string>core.NonNullParamChecker</string>
61536153
<!-- This hash is experimental and going to change! -->
6154-
<key>issue_hash_content_of_line_in_context</key><string>c0b359a043c633f1b8d1581f68743361</string>
6154+
<key>issue_hash_content_of_line_in_context</key><string>4c580a2a9cf15947fa485a0a9e625306</string>
61556155
<key>issue_context_kind</key><string>function</string>
61566156
<key>issue_context</key><string>RDar13295437</string>
61576157
<key>issue_hash_function_offset</key><string>3</string>

clang/test/Analysis/const-method-call.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
1+
// RUN: %clang_analyze_cc1 -Wno-error=return-type -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
22

33
void clang_analyzer_eval(bool);
44

clang/test/Analysis/inline-unique-reports.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -Wno-error=implicit-int -o %t > /dev/null 2>&1
1+
// RUN: %clang_analyze_cc1 %s -analyzer-checker=core.NullDereference -analyzer-output=plist -Wno-error=implicit-int -Wno-error=return-type -o %t > /dev/null 2>&1
22
// RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/inline-unique-reports.c.plist -
33

44
static inline bug(int *p) {

clang/test/Analysis/malloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,8 +1914,8 @@ variable 'buf', which is not memory allocated by 'malloc()' [unix.Malloc]}}
19141914

19151915
(*crash_a)(); // expected-warning{{type specifier missing}}
19161916
// A CallEvent without a corresponding FunctionDecl.
1917-
crash_b() { crash_a(); } // no-crash
1918-
// expected-warning@-1{{type specifier missing}} expected-warning@-1{{non-void}}
1917+
crash_b() { crash_a(); return 0; } // no-crash
1918+
// expected-warning@-1{{type specifier missing}}
19191919

19201920
long *global_a;
19211921
void realloc_crash(void) {

0 commit comments

Comments
 (0)