From d34c42ec864fda391a7c92bfbee02e30882f9cc7 Mon Sep 17 00:00:00 2001 From: zhaoxuhui Date: Tue, 27 Jun 2023 09:35:47 +0800 Subject: [PATCH] [BSC] bugfix for return instantiated struct --- clang/lib/Sema/SemaInit.cpp | 3 --- .../return_type_instantiated_struct1.cbs | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 clang/test/BSC/Generic/StructAndFunction/return_type_instantiated_struct1.cbs diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index fb04a431c2af..bf7ca718a36b 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -5926,9 +5926,6 @@ void InitializationSequence::InitializeFrom(Sema &S, // We're at the end of the line for C: it's either a write-back conversion // or it's a C assignment. There's no need to check anything else. if (!S.getLangOpts().CPlusPlus) { - if (S.getLangOpts().BSC && DestType->getAsCXXRecordDecl()) - return; - // If allowed, check whether this is an Objective-C writeback conversion. if (allowObjCWritebackConversion && tryObjCWritebackConversion(S, *this, Entity, Initializer)) { diff --git a/clang/test/BSC/Generic/StructAndFunction/return_type_instantiated_struct1.cbs b/clang/test/BSC/Generic/StructAndFunction/return_type_instantiated_struct1.cbs new file mode 100644 index 000000000000..258aa536e758 --- /dev/null +++ b/clang/test/BSC/Generic/StructAndFunction/return_type_instantiated_struct1.cbs @@ -0,0 +1,25 @@ +// RUN: %clang %s -o %t.output +// RUN: %t.output +// expected-no-diagnostics + +struct PollResult { + _Bool isPending; +}; + +struct PollResult poll() { + struct PollResult s; + return s; +} + +void struct PollResult::foo(struct PollResult *this) { +} + + +int main() { + struct PollResult (*pollFunc)() = int::poll; + struct PollResult res = pollFunc(); + if (res.isPending) { + res.foo(); + } + return 0; +} -- Gitee