[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-17 Thread Cyndy Ishida via cfe-commits


@@ -,8 +,15 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
 }
   }
 
-  if (SS.isEmpty())
+  if (SS.isEmpty()) {
+if (getLangOpts().ObjC && !getLangOpts().CPlusPlus &&

cyndyishida wrote:

I'm wondering if it's valid for C code to enter this block, iow, can we remove 
the `getLangOpts().ObjC` check? 
I notice a similar check in  
https://github.com/llvm/llvm-project/blob/ec903eb3fcd18ba53af901582060bd61b13cf324/clang/lib/Parse/Parser.cpp#L2170
 that also looks added to resolve a hang. 

https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-17 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

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,
```objective-c
@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.

https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-17 Thread via cfe-commits

cor3ntin wrote:

> 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++

https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-16 Thread Volodymyr Sapsai via cfe-commits

vsapsai wrote:

How does it work in Objective-C++? I don't know even if we have a test but hope 
we do.

https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-16 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

This should have a release note.

https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-16 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/119908

>From 63c424414c1814ec9b4c3c5a459bfe1be684586d Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Fri, 13 Dec 2024 09:41:41 -0800
Subject: [PATCH 1/2] Fix parsing :: in method parameter type.

---
 clang/lib/Parse/Parser.cpp  | 8 +++-
 clang/test/Parser/objc-coloncolon.m | 5 +
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/objc-coloncolon.m

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
@@ -,8 +,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 00..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

>From ec903eb3fcd18ba53af901582060bd61b13cf324 Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Mon, 16 Dec 2024 09:34:52 -0800
Subject: [PATCH 2/2] Fix ObjectiveC++

---
 clang/lib/Parse/Parser.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index aa78d702553172..8ba6a5dce8a994 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2223,7 +2223,8 @@ bool Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(
   }
 
   if (SS.isEmpty()) {
-if (getLangOpts().ObjC && Tok.is(tok::coloncolon)) {
+if (getLangOpts().ObjC && !getLangOpts().CPlusPlus &&
+Tok.is(tok::coloncolon)) {
   // ObjectiveC does not allow :: as as a scope token.
   Diag(ConsumeToken(), diag::err_expected_type);
   return true;

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-13 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

This fix tripped some tests in `libc++`. I am investigating. 

https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-13 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu edited 
https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qiongsi Wu (qiongsiwu)


Changes

The parser hangs when processing method parameters with types prefixed by `::`. 
For example, 
```
- (instancetype)init:(::A *) foo;
```

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:

- (modified) clang/lib/Parse/Parser.cpp (+7-1) 
- (added) clang/test/Parser/objc-coloncolon.m (+5) 


``diff
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
@@ -,8 +,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 00..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

``




https://github.com/llvm/llvm-project/pull/119908
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][ObjectiveC] Fix Parsing Method Parameter Types with the `::` Prefix (PR #119908)

2024-12-13 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu created 
https://github.com/llvm/llvm-project/pull/119908

The parser hangs when processing method parameters with types prefixed by `::`. 
For example, 
```
- (instancetype)init:(::A *) foo;
```

The parser should not hang, and it should emit an error. This PR implements the 
error check. 

>From 63c424414c1814ec9b4c3c5a459bfe1be684586d Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Fri, 13 Dec 2024 09:41:41 -0800
Subject: [PATCH] Fix parsing :: in method parameter type.

---
 clang/lib/Parse/Parser.cpp  | 8 +++-
 clang/test/Parser/objc-coloncolon.m | 5 +
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Parser/objc-coloncolon.m

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
@@ -,8 +,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 00..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

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits