-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][ObjectiveC] Fix Parsing the ::
Optional Scope Specifier
#119908
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
Conversation
@llvm/pr-subscribers-clang Author: Qiongsi Wu (qiongsiwu) ChangesThe parser hangs when processing method parameters with types prefixed by
The parser should not hang, and it should emit an error. This PR implements the error check. Full diff: https://github.com/llvm/llvm-project/pull/119908.diff 2 Files Affected:
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 36e56a92c3092e..aa78d702553172 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2222,8 +2222,14 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
}
}
- if (SS.isEmpty())
+ if (SS.isEmpty()) {
+ if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+ // ObjectiveC does not allow :: as as a scope token.
+ Diag(ConsumeToken(), diag::err_expected_type);
+ return true;
+ }
return false;
+ }
// A C++ scope specifier that isn't followed by a typename.
AnnotateScopeToken(SS, IsNewScope);
diff --git a/clang/test/Parser/objc-coloncolon.m b/clang/test/Parser/objc-coloncolon.m
new file mode 100644
index 00000000000000..e8a09898263bb3
--- /dev/null
+++ b/clang/test/Parser/objc-coloncolon.m
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -verify %s
+
+@interface A
+- (instancetype)init:(::A *) foo; // expected-error {{expected a type}}
+@end
|
This fix tripped some tests in |
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.
This should have a release note.
How does it work in Objective-C++? I don't know even if we have a test but hope we do. |
Right, this needs tests for Objective-C++ |
I don't know if we have a test for it but I've realized there are cases where you can have a legitimate double colon in Objective-C. For example, @interface NSObject
@end
@implementation NSObject
- (void)performSelector:(SEL)selector {}
- (void)double:(int)firstArg :(int)secondArg colon:(int)thirdArg {}
- (void)test {
[self performSelector:@selector(double::colon:)];
}
@end It's not a method parameter type, so it is possible your code isn't executed. But it is worth checking if we test this case. |
::
Prefix::
Optional Scope Specifier
Thanks for the feedback everyone! The PR is updated to address the review comments.
|
The Objective-C test is modified to contain valid code with |
Gentle ping for review. Thanks so much! |
::
Optional Scope Specifier::
Optional Scope Specifier
(https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it/74223 the convention is to disable github's hide-email feature) |
…vm#119908) The parser hangs when processing types/variables prefixed by `::` as an optional scope specifier. For example, ``` - (instancetype)init:(::A *) foo; ``` The parser should not hang, and it should emit an error. This PR implements the error check. rdar://140885078 (cherry picked from commit 1418018)
…on_fix [clang][ObjectiveC] Fix Parsing the `::` Optional Scope Specifier (llvm#119908)
The parser hangs when processing types/variables prefixed by
::
as an optional scope specifier. For example,The parser should not hang, and it should emit an error. This PR implements the error check.
rdar://140885078