From defa3bf4c87132d6963c0f65d158c886b4d4c97a Mon Sep 17 00:00:00 2001 From: zhaoxuhui Date: Wed, 18 Jan 2023 19:39:34 +0800 Subject: [PATCH] add test case --- clang/test/BSC/pending/CallBeforeDefine.cbs | 17 +++++++++++++ clang/test/BSC/pending/InstanceMemberFunc.cbs | 17 +++++++++++++ clang/test/BSC/pending/OverloadFunc.cbs | 24 ++++++++++++++++++ clang/test/BSC/pending/StaticMemberFunc.cbs | 20 +++++++++++++++ clang/test/BSC/pending/ThisParamCheck1.cbs | 17 +++++++++++++ clang/test/BSC/pending/ThisParamCheck2.cbs | 21 ++++++++++++++++ clang/test/BSC/pending/Typedef.cbs | 25 +++++++++++++++++++ clang/test/lit.cfg.py | 2 +- .../Frontend/CompilerInvocationTest.cpp | 10 ++++++++ 9 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 clang/test/BSC/pending/CallBeforeDefine.cbs create mode 100644 clang/test/BSC/pending/InstanceMemberFunc.cbs create mode 100644 clang/test/BSC/pending/OverloadFunc.cbs create mode 100644 clang/test/BSC/pending/StaticMemberFunc.cbs create mode 100644 clang/test/BSC/pending/ThisParamCheck1.cbs create mode 100644 clang/test/BSC/pending/ThisParamCheck2.cbs create mode 100644 clang/test/BSC/pending/Typedef.cbs diff --git a/clang/test/BSC/pending/CallBeforeDefine.cbs b/clang/test/BSC/pending/CallBeforeDefine.cbs new file mode 100644 index 000000000000..c8e9187030a7 --- /dev/null +++ b/clang/test/BSC/pending/CallBeforeDefine.cbs @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics +typedef struct Foo { + int a; +}Foo; + +int Foo::getA(struct Foo* this); + +int main() { + struct Foo foo; + foo.a = 42; + return foo.getA(); +} + +int Foo::getA(struct Foo* this) { + return this->a; +} \ No newline at end of file diff --git a/clang/test/BSC/pending/InstanceMemberFunc.cbs b/clang/test/BSC/pending/InstanceMemberFunc.cbs new file mode 100644 index 000000000000..0cdd03d421b1 --- /dev/null +++ b/clang/test/BSC/pending/InstanceMemberFunc.cbs @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics +typedef struct Foo{ + int a; +}Foo; + +int Foo::getA(struct Foo* this) { + return this->a; +} + +int main() { + Foo foo; + foo.a = 42; + foo.getA(); + Foo::getA(&foo); + return 0; +} \ No newline at end of file diff --git a/clang/test/BSC/pending/OverloadFunc.cbs b/clang/test/BSC/pending/OverloadFunc.cbs new file mode 100644 index 000000000000..442a57b87669 --- /dev/null +++ b/clang/test/BSC/pending/OverloadFunc.cbs @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct Foo { + int a; +}; +typedef struct Foo F; + +int F::f2(F* this) { +// expected-note@-1 {{previous definition is here}} +// expected-note@-2 {{passing argument to parameter 'this' here}} + return 1; +} + +int F::f2(F* this, int a) { // expected-error {{conflicting types for 'f2'}} + return a; +} + +int main(){ + Foo foo; + foo.a = 1; + foo.f2(); + foo.f2(1); // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'F *' (aka 'struct Foo *')}} + return 0; +} \ No newline at end of file diff --git a/clang/test/BSC/pending/StaticMemberFunc.cbs b/clang/test/BSC/pending/StaticMemberFunc.cbs new file mode 100644 index 000000000000..f9b2068cfd7e --- /dev/null +++ b/clang/test/BSC/pending/StaticMemberFunc.cbs @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics +typedef struct Foo{ + int a; +}Foo; + +int Foo::s1() { + return 1; +} + +int Foo::s2(struct Foo* other) { + return other->a; +} + +int main() { + struct Foo x = {0}; + Foo::s1(); + Foo::s2(&x); + return 0; +} \ No newline at end of file diff --git a/clang/test/BSC/pending/ThisParamCheck1.cbs b/clang/test/BSC/pending/ThisParamCheck1.cbs new file mode 100644 index 000000000000..05281fbfb1fb --- /dev/null +++ b/clang/test/BSC/pending/ThisParamCheck1.cbs @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef struct Foo { + int a; +}Foo; + +typedef struct Bar { + int a; +}Bar; + +int Foo::getA(int b, struct Foo* this) { // expected-error {{'this' cannot be the name of a parameter}} + return this->a; +} + +int Foo::getBarA(struct Bar* this) { // expected-error {{struct Bar * is not supported on this target}} + return this->a; +} \ No newline at end of file diff --git a/clang/test/BSC/pending/ThisParamCheck2.cbs b/clang/test/BSC/pending/ThisParamCheck2.cbs new file mode 100644 index 000000000000..1fee3762a580 --- /dev/null +++ b/clang/test/BSC/pending/ThisParamCheck2.cbs @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +typedef struct Foo{ + int a; +}Foo; + +int Foo::s1() { + return 1; +} + +int Foo::s2(struct Foo* other) { + return other->a; +} + +int main() { + struct Foo x = {0}; + x.s1(); // expected-error {{no member named 's1' in 'struct Foo'; did you mean to use '::' instead of '.'?}} + + x.s2(); // expected-error {{no member named 's2' in 'struct Foo'; did you mean to use '::' instead of '.'?}} + return 0; +} \ No newline at end of file diff --git a/clang/test/BSC/pending/Typedef.cbs b/clang/test/BSC/pending/Typedef.cbs new file mode 100644 index 000000000000..ee779a449bcb --- /dev/null +++ b/clang/test/BSC/pending/Typedef.cbs @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics +struct Foo { + int a; + int b; +}; +typedef struct Foo Foo; + +int Foo::getB(Foo* this) { + return this->b; +} + +int Foo::getAPlusB(struct Foo* this) { + return this->a + this->b; +} + +int main() { + Foo foo; + foo.a = 42; + foo.b = 2023; + int b = foo.getB(); + int ab = foo.getAPlusB(); + return 0; +} + diff --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py index 863ab444fb02..b99a6dacb05d 100644 --- a/clang/test/lit.cfg.py +++ b/clang/test/lit.cfg.py @@ -26,7 +26,7 @@ config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) # suffixes: A list of file extensions to treat as test files. config.suffixes = ['.c', '.cpp', '.i', '.cppm', '.m', '.mm', '.cu', - '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs'] + '.ll', '.cl', '.s', '.S', '.modulemap', '.test', '.rs', '.ifs', '.cbs'] # excludes: A list of directories to exclude from the testsuite. The 'Inputs' # subdirectories contain auxiliary inputs for various tests in their parent diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 4b042b525d38..268f0d0dca45 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -730,4 +730,14 @@ TEST_F(CommandLineTest, DigraphsNotImplied) { ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-digraphs")))); ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fdigraphs")))); } + +TEST_F(CommandLineTest, DigraphsEnabled) { + const char *Args[] = {"-std=c89", "-fdigraphs"}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); + ASSERT_TRUE(Invocation.getLangOpts()->Digraphs); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fdigraphs"))); +} } // anonymous namespace -- Gitee