From 8f04c23b0c53dd9721926bf232c9578c9bd94683 Mon Sep 17 00:00:00 2001 From: liuxinyi Date: Tue, 18 Jun 2024 15:16:22 +0800 Subject: [PATCH] bugfix --- clang/include/clang/Parse/Parser.h | 1 - clang/lib/Parse/ParseDecl.cpp | 30 ++++----- .../call_undefined_func.cbs | 5 +- .../Constant_func_3/Constant_func_3.cbs | 65 +++++++++++++++++++ 4 files changed, 83 insertions(+), 18 deletions(-) create mode 100644 clang/test/BSC/Positive/Generic/Constant/Constant_func_3/Constant_func_3.cbs diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index c9b01c66d1de..7ad272360665 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1929,7 +1929,6 @@ private: case tok::equal: case tok::l_brace: case tok::semi: - case tok::numeric_constant: return true; default: diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 7f9a42960ebb..3b04389c004f 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -6447,6 +6447,21 @@ void Parser::ParseDirectDeclarator(Declarator &D) { #endif ) && D.mayHaveIdentifier()) { + #if ENABLE_BSC + if (IsParsingBSCGenericParameters) { + Token SwitchTok = PP.LookAhead(BSCGenericLookAhead); + UnqualifiedId &Result = D.getName(); + if (SwitchTok.is(tok::identifier)) { + IdentifierInfo *Id = SwitchTok.getIdentifierInfo(); + SourceLocation IdLoc = SwitchTok.getLocation(); + Result.setIdentifier(Id, IdLoc); + BSCGenericLookAhead++; + } + D.SetRangeEnd(D.getName().getSourceRange().getEnd()); + goto PastIdentifier; + } + #endif + // This might be a C++17 structured binding. if (Tok.is(tok::l_square) && !D.mayOmitIdentifier() && D.getCXXScopeSpec().isEmpty()) @@ -6515,21 +6530,6 @@ void Parser::ParseDirectDeclarator(Declarator &D) { // the l_paren token. } - #if ENABLE_BSC - if (IsParsingBSCGenericParameters) { - Token SwitchTok = PP.LookAhead(BSCGenericLookAhead); - UnqualifiedId &Result = D.getName(); - if (SwitchTok.is(tok::identifier)) { - IdentifierInfo *Id = SwitchTok.getIdentifierInfo(); - SourceLocation IdLoc = SwitchTok.getLocation(); - Result.setIdentifier(Id, IdLoc); - BSCGenericLookAhead++; - } - D.SetRangeEnd(D.getName().getSourceRange().getEnd()); - goto PastIdentifier; - } - #endif - if (Tok.isOneOf(tok::identifier, tok::kw_operator, tok::annot_template_id, tok::tilde)) { // We found something that indicates the start of an unqualified-id. diff --git a/clang/test/BSC/Negative/Trait/GenericTrait/call_undefined_func/call_undefined_func.cbs b/clang/test/BSC/Negative/Trait/GenericTrait/call_undefined_func/call_undefined_func.cbs index f64846596ca1..f8f89e961f2a 100644 --- a/clang/test/BSC/Negative/Trait/GenericTrait/call_undefined_func/call_undefined_func.cbs +++ b/clang/test/BSC/Negative/Trait/GenericTrait/call_undefined_func/call_undefined_func.cbs @@ -13,6 +13,7 @@ impl trait F for int; int main() { int a = 1; trait F* f = &a; - f->get(); // expected-error {{no member named 'get' in 'struct __Trait_F_Vtable'}} + // f->get(); // expected-error {{no member named 'get' in 'struct __Trait_F_Vtable'}} + f->get(); // expected-error {{'struct __Trait_F_Vtable'}} return 0; -} +} \ No newline at end of file diff --git a/clang/test/BSC/Positive/Generic/Constant/Constant_func_3/Constant_func_3.cbs b/clang/test/BSC/Positive/Generic/Constant/Constant_func_3/Constant_func_3.cbs new file mode 100644 index 000000000000..39ab647df653 --- /dev/null +++ b/clang/test/BSC/Positive/Generic/Constant/Constant_func_3/Constant_func_3.cbs @@ -0,0 +1,65 @@ +// RUN: %clang %s -o %t.output +// RUN: %t.output +// RUN: %clang -rewrite-bsc %s -o %t-rw.c +// RUN: %clang %t-rw.c -o %t-rw.output +// RUN: %t-rw.output +// expected-no-diagnostics + +struct S1 {}; +typedef MyS1 = struct S1; + +struct S2 {}; +typedef MyS2 = struct S2; + +S1<5> foo1() { + S1<5> s; + return s; +} + +S1 foo2() { + S1 s; + return s; +} + +MyS1<5> foo3() { + MyS1<5> s; + return s; +} + +MyS1 foo4() { + MyS1 s; + return s; +} + +S2 foo5() { + S2 s; + return s; +} + +S2 foo6() { + S2 s; + return s; +} + +MyS2 foo7() { + MyS2 s; + return s; +} + +MyS2 foo8() { + MyS2 s; + return s; +} + +int main() { + S1<5> s1 = foo1(); + S1<5> s2 = foo2<5, int>(); + MyS1<5> s3 = foo3(); + MyS1<5> s4 = foo4<5, int>(); + + S2 s5 = foo5<5>(); + S2 s6 = foo6<5, int>(); + MyS2 s7 = foo7<5>(); + MyS2 s8 = foo8<5, int>(); + return 0; +} \ No newline at end of file -- Gitee