-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[Bounds Safety][NFC] Add some missing coverage for -fexperimental-late-parse-attributes
#102236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bounds Safety][NFC] Add some missing coverage for -fexperimental-late-parse-attributes
#102236
Conversation
@llvm/pr-subscribers-clang Author: Dan Liew (delcypher) ChangesPreviously we weren't properly checking that using For example we weren't testing that the attribute appearing in the type position generated the right AST with This patch adds additional rdar://133325597 Full diff: https://github.com/llvm/llvm-project/pull/102236.diff 21 Files Affected:
diff --git a/clang/test/AST/attr-counted-by-or-null-struct-ptrs.c b/clang/test/AST/attr-counted-by-or-null-struct-ptrs.c
index cedb3f1192eda..075f583784fe1 100644
--- a/clang/test/AST/attr-counted-by-or-null-struct-ptrs.c
+++ b/clang/test/AST/attr-counted-by-or-null-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes %s -ast-dump | FileCheck %s
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
diff --git a/clang/test/AST/attr-counted-by-struct-ptrs.c b/clang/test/AST/attr-counted-by-struct-ptrs.c
index 79a453d239cd5..0c05258234143 100644
--- a/clang/test/AST/attr-counted-by-struct-ptrs.c
+++ b/clang/test/AST/attr-counted-by-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes %s -ast-dump | FileCheck %s
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/AST/attr-sized-by-or-null-struct-ptrs.c b/clang/test/AST/attr-sized-by-or-null-struct-ptrs.c
index 6189799b85ccb..73b8a71f23503 100644
--- a/clang/test/AST/attr-sized-by-or-null-struct-ptrs.c
+++ b/clang/test/AST/attr-sized-by-or-null-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes %s -ast-dump | FileCheck %s
#define __sized_by_or_null(f) __attribute__((sized_by_or_null(f)))
diff --git a/clang/test/AST/attr-sized-by-struct-ptrs.c b/clang/test/AST/attr-sized-by-struct-ptrs.c
index 5d9ed0094c685..7f7e3dfea2ac7 100644
--- a/clang/test/AST/attr-sized-by-struct-ptrs.c
+++ b/clang/test/AST/attr-sized-by-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes %s -ast-dump | FileCheck %s
#define __sized_by(f) __attribute__((sized_by(f)))
diff --git a/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c
index 7d9c9a90880ff..5a739f9c6bc04 100644
--- a/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c
+++ b/clang/test/Sema/attr-counted-by-bounds-safety-vlas.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fexperimental-bounds-safety -fexperimental-late-parse-attributes -verify %s
//
// This is a portion of the `attr-counted-by-vla.c` test but is checked
// under the semantics of `-fexperimental-bounds-safety` which has different
diff --git a/clang/test/Sema/attr-counted-by-or-null-last-field.c b/clang/test/Sema/attr-counted-by-or-null-last-field.c
index dd3a6422521c0..c906b4b6c4b07 100644
--- a/clang/test/Sema/attr-counted-by-or-null-last-field.c
+++ b/clang/test/Sema/attr-counted-by-or-null-last-field.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DLATE_PARSING_ENABLED -fsyntax-only -fexperimental-late-parse-attributes -verify %s
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
@@ -80,10 +81,17 @@ struct found_outside_of_struct {
struct bar ** ptr __counted_by_or_null(global); // expected-error {{field 'global' in 'counted_by_or_null' not inside structure}}
};
+#ifndef LATE_PARSING_ENABLED
struct self_referrential {
int bork;
struct bar *self[] __counted_by_or_null(self); // expected-error {{use of undeclared identifier 'self'}}
};
+#else
+struct self_referrential {
+ int bork;
+ struct bar *self[] __counted_by_or_null(self); // expected-error {{'counted_by_or_null' only applies to pointers; did you mean to use 'counted_by'?}}
+};
+#endif
struct non_int_count {
double dbl_count;
diff --git a/clang/test/Sema/attr-counted-by-or-null-struct-ptrs-sizeless-types.c b/clang/test/Sema/attr-counted-by-or-null-struct-ptrs-sizeless-types.c
index 301977300b06a..4b898e7369c19 100644
--- a/clang/test/Sema/attr-counted-by-or-null-struct-ptrs-sizeless-types.c
+++ b/clang/test/Sema/attr-counted-by-or-null-struct-ptrs-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
diff --git a/clang/test/Sema/attr-counted-by-or-null-struct-ptrs.c b/clang/test/Sema/attr-counted-by-or-null-struct-ptrs.c
index 017aafe0c9396..708bb727ce09d 100644
--- a/clang/test/Sema/attr-counted-by-or-null-struct-ptrs.c
+++ b/clang/test/Sema/attr-counted-by-or-null-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/Sema/attr-counted-by-or-null-vla-sizeless-types.c b/clang/test/Sema/attr-counted-by-or-null-vla-sizeless-types.c
index 8abd4476fe597..1e8c7179e7903 100644
--- a/clang/test/Sema/attr-counted-by-or-null-vla-sizeless-types.c
+++ b/clang/test/Sema/attr-counted-by-or-null-vla-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __counted_by_or_null(f) __attribute__((counted_by_or_null(f)))
diff --git a/clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c b/clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
index 9b0f2eafb13c2..1de93640cf458 100644
--- a/clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
+++ b/clang/test/Sema/attr-counted-by-struct-ptrs-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/Sema/attr-counted-by-struct-ptrs.c b/clang/test/Sema/attr-counted-by-struct-ptrs.c
index cd2bfe36938b2..a35d4fcf02a58 100644
--- a/clang/test/Sema/attr-counted-by-struct-ptrs.c
+++ b/clang/test/Sema/attr-counted-by-struct-ptrs.c
@@ -1,4 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// Test that in late parsing mode attributes that don't require late parsing
+// are handled correctly
+// RUN: %clang_cc1 -fsyntax-only -fexperimental-late-parse-attributes %s -verify
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/Sema/attr-counted-by-vla-sizeless-types.c b/clang/test/Sema/attr-counted-by-vla-sizeless-types.c
index 31c0007501c48..8cc5f64482548 100644
--- a/clang/test/Sema/attr-counted-by-vla-sizeless-types.c
+++ b/clang/test/Sema/attr-counted-by-vla-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple arm64-apple-darwin -fexperimental-late-parse-attributes -fsyntax-only -verify %s
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/Sema/attr-counted-by-vla.c b/clang/test/Sema/attr-counted-by-vla.c
index 571d6e6291e6b..de450944211ec 100644
--- a/clang/test/Sema/attr-counted-by-vla.c
+++ b/clang/test/Sema/attr-counted-by-vla.c
@@ -1,4 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// Test that in late parsing mode attributes that don't require late parsing
+// still parse correctly.
+// RUN: %clang_cc1 -DLATE_PARSING_ENABLED -fsyntax-only -fexperimental-late-parse-attributes %s -verify
#define __counted_by(f) __attribute__((counted_by(f)))
@@ -78,10 +81,17 @@ struct found_outside_of_struct {
struct bar *fam[] __counted_by(global); // expected-error {{field 'global' in 'counted_by' not inside structure}}
};
+#ifndef LATE_PARSING_ENABLED
struct self_referrential {
int bork;
struct bar *self[] __counted_by(self); // expected-error {{use of undeclared identifier 'self'}}
};
+#else
+struct self_referrential {
+ int bork;
+ struct bar *self[] __counted_by(self); // expected-error {{'counted_by' requires a non-boolean integer type argument}}
+};
+#endif
struct non_int_count {
double dbl_count;
diff --git a/clang/test/Sema/attr-sized-by-last-field.c b/clang/test/Sema/attr-sized-by-last-field.c
index 6af29e9f31435..35be22f888939 100644
--- a/clang/test/Sema/attr-sized-by-last-field.c
+++ b/clang/test/Sema/attr-sized-by-last-field.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DLATE_PARSING_ENABLED -fexperimental-late-parse-attributes -fsyntax-only -verify %s
#define __sized_by(f) __attribute__((sized_by(f)))
@@ -80,10 +81,17 @@ struct found_outside_of_struct {
struct bar ** ptr __sized_by(global); // expected-error {{field 'global' in 'sized_by' not inside structure}}
};
+#ifndef LATE_PARSING_ENABLED
struct self_referrential {
int bork;
struct bar *self[] __sized_by(self); // expected-error {{use of undeclared identifier 'self'}}
};
+#else
+struct self_referrential {
+ int bork;
+ struct bar *self[] __sized_by(self); // expected-error {{'sized_by' only applies to pointers; did you mean to use 'counted_by'?}}
+};
+#endif
struct non_int_size {
double dbl_size;
diff --git a/clang/test/Sema/attr-sized-by-or-null-last-field.c b/clang/test/Sema/attr-sized-by-or-null-last-field.c
index 96bbe847b910b..7322a7d9f6c25 100644
--- a/clang/test/Sema/attr-sized-by-or-null-last-field.c
+++ b/clang/test/Sema/attr-sized-by-or-null-last-field.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -DLATE_PARSING_ENABLED -fsyntax-only -fexperimental-late-parse-attributes -verify %s
#define __sized_by_or_null(f) __attribute__((sized_by_or_null(f)))
@@ -80,10 +81,17 @@ struct found_outside_of_struct {
struct bar ** ptr __sized_by_or_null(global); // expected-error {{field 'global' in 'sized_by_or_null' not inside structure}}
};
+#ifndef LATE_PARSING_ENABLED
struct self_referrential {
int bork;
struct bar *self[] __sized_by_or_null(self); // expected-error {{use of undeclared identifier 'self'}}
};
+#else
+struct self_referrential {
+ int bork;
+ struct bar *self[] __sized_by_or_null(self); // expected-error {{'sized_by_or_null' only applies to pointers; did you mean to use 'counted_by'?}}
+};
+#endif
struct non_int_size {
double dbl_size;
diff --git a/clang/test/Sema/attr-sized-by-or-null-struct-ptrs-sizeless-types.c b/clang/test/Sema/attr-sized-by-or-null-struct-ptrs-sizeless-types.c
index 4a360b9722a0b..d960c0d31b65c 100644
--- a/clang/test/Sema/attr-sized-by-or-null-struct-ptrs-sizeless-types.c
+++ b/clang/test/Sema/attr-sized-by-or-null-struct-ptrs-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __sized_by_or_null(f) __attribute__((sized_by_or_null(f)))
diff --git a/clang/test/Sema/attr-sized-by-or-null-struct-ptrs.c b/clang/test/Sema/attr-sized-by-or-null-struct-ptrs.c
index 2c7578b5ecbe6..4200c9275a180 100644
--- a/clang/test/Sema/attr-sized-by-or-null-struct-ptrs.c
+++ b/clang/test/Sema/attr-sized-by-or-null-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s
#define __sized_by_or_null(f) __attribute__((sized_by_or_null(f)))
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/Sema/attr-sized-by-or-null-vla-sizeless-types.c b/clang/test/Sema/attr-sized-by-or-null-vla-sizeless-types.c
index 398b1df592fe3..7d16c2d456a02 100644
--- a/clang/test/Sema/attr-sized-by-or-null-vla-sizeless-types.c
+++ b/clang/test/Sema/attr-sized-by-or-null-vla-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __sized_by_or_null(f) __attribute__((sized_by_or_null(f)))
diff --git a/clang/test/Sema/attr-sized-by-struct-ptrs-sizeless-types.c b/clang/test/Sema/attr-sized-by-struct-ptrs-sizeless-types.c
index 2e916bdb04720..7038330e60eee 100644
--- a/clang/test/Sema/attr-sized-by-struct-ptrs-sizeless-types.c
+++ b/clang/test/Sema/attr-sized-by-struct-ptrs-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __sized_by(f) __attribute__((sized_by(f)))
diff --git a/clang/test/Sema/attr-sized-by-struct-ptrs.c b/clang/test/Sema/attr-sized-by-struct-ptrs.c
index 01195469c6fe4..07373b247d0f7 100644
--- a/clang/test/Sema/attr-sized-by-struct-ptrs.c
+++ b/clang/test/Sema/attr-sized-by-struct-ptrs.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify %s
#define __sized_by(f) __attribute__((sized_by(f)))
#define __counted_by(f) __attribute__((counted_by(f)))
diff --git a/clang/test/Sema/attr-sized-by-vla-sizeless-types.c b/clang/test/Sema/attr-sized-by-vla-sizeless-types.c
index 37e91639bb4a1..8a94b1217c906 100644
--- a/clang/test/Sema/attr-sized-by-vla-sizeless-types.c
+++ b/clang/test/Sema/attr-sized-by-vla-sizeless-types.c
@@ -1,5 +1,6 @@
// __SVInt8_t is specific to ARM64 so specify that in the target triple
// RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -triple arm64-apple-darwin -fsyntax-only -verify %s
#define __sized_by(f) __attribute__((sized_by(f)))
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the additional test coverage! I have some suggestions on how to improve a few of the tests.
…te-parse-attributes` Previously we weren't properly checking that using `-fexperimental-late-parse-attributes` worked on source code that didn't need late parsing. For example we weren't testing that the attribute appearing in the type position generated the right AST with `-fexperimental-late-parse-attributes` on. This patch adds additional `RUN` lines to re-run the relevant test cases with `-fexperimental-late-parse-attributes` enabled. rdar://133325597
a12ee19
to
0051d3b
Compare
@AaronBallman Thanks for the feedback. I've tried to make your suggested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Previously we weren't properly checking that using
-fexperimental-late-parse-attributes
worked on source code that didn't need late parsing.For example we weren't testing that the attribute appearing in the type position generated the right AST with
-fexperimental-late-parse-attributes
on or off.This patch adds additional
RUN
lines to re-run the relevant test cases with-fexperimental-late-parse-attributes
enabled.rdar://133325597