From cfe-commits Thu Jan 08 21:12:40 2015 From: Olivier Goffart Date: Thu, 08 Jan 2015 21:12:40 +0000 To: cfe-commits Subject: [PATCH] Fix crash in typo correction while correcting enum within a struct in C Message-Id: <1864234.8JDiSoNOGn () finn> X-MARC-Message: https://marc.info/?l=cfe-commits&m=142075189824324 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--nextPart3428109.r8vhdgtsoi" This is a multi-part message in MIME format. --nextPart3428109.r8vhdgtsoi Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Hi, Please review the attached patch. It fix a crash while trying to compile the code that is in the testcase (in C mode). This crash is a regression since 3.5 The problem is that "isCXXClassMember" for the NameDecl of the enum values returns true even tough we are in C mode. Therefore, the DeclContext is not a CXXRecordDecl, but just a plain RecordDecl. I'm taking the least intrusive approach by handling the case in which the cast would otherwise fail. Thanks -- Olivier --nextPart3428109.r8vhdgtsoi Content-Disposition: attachment; filename="0001-Fix-crash-in-typo-correction-while-correcting-enum-w.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-Fix-crash-in-typo-correction-while-correcting-enum-w.patch" From 64b19f4397b75a68ba5a0e6054fefc2e4ab6ad06 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 8 Jan 2015 21:50:52 +0100 Subject: [PATCH] Fix crash in typo correction while correcting enum within a struct in C --- lib/Sema/SemaExprCXX.cpp | 5 +++-- test/Sema/typo-correction.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 6351b7d..750a40e 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -5991,8 +5991,9 @@ static ExprResult attemptRecovery(Sema &SemaRef, if (auto *NNS = TC.getCorrectionSpecifier()) Record = NNS->getAsType()->getAsCXXRecordDecl(); if (!Record) - Record = cast(ND->getDeclContext()->getRedeclContext()); - R.setNamingClass(Record); + Record = dyn_cast(ND->getDeclContext()->getRedeclContext()); + if (Record) + R.setNamingClass(Record); // Detect and handle the case where the decl might be an implicit // member. diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index e4d1465..4fbc38f 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -12,3 +12,15 @@ void PR21656() { a = b ? : 0; // expected-warning {{type specifier missing, defaults to 'int'}} \ // expected-error {{use of undeclared identifier 'b'}} + + +struct ContainerStuct { + enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}} +}; + +void func(int arg) +{ + switch (arg) { + case SOME_ENUM_: ; // expected-error {{use of undeclared identifier 'SOME_ENUM_'; did you mean 'SOME_ENUM'}} + } +} -- 2.2.1 --nextPart3428109.r8vhdgtsoi Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits --nextPart3428109.r8vhdgtsoi--