Author: mren Date: Thu Feb 4 14:05:40 2016 New Revision: 259820 URL: http://llvm.org/viewvc/llvm-project?rev=259820&view=rev Log: Fix a crash when there is a typo in the return statement.
If the typo happens after a successful deduction for an earlier return statement, we should check if the deduced type is null before using it. The typo correction happens after we try to deduce the return type and we ignore the deduction from the typo and continue to typo correction. rdar://24342247 Added: cfe/trunk/test/SemaCXX/typo-correction-crash.cpp Modified: cfe/trunk/lib/Sema/SemaStmt.cpp Modified: cfe/trunk/lib/Sema/SemaStmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=259820&r1=259819&r2=259820&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaStmt.cpp (original) +++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Feb 4 14:05:40 2016 @@ -3069,6 +3069,11 @@ bool Sema::DeduceFunctionTypeFromReturnE QualType DeducedT = AT->getDeducedType(); if (!DeducedT.isNull() && !FD->isInvalidDecl()) { AutoType *NewAT = Deduced->getContainedAutoType(); + // It is possible that NewAT->getDeducedType() is null. When that happens, + // we should not crash, instead we ignore this deduction. + if (NewAT->getDeducedType().isNull()) + return false; + CanQualType OldDeducedType = Context.getCanonicalFunctionResultType( DeducedT); CanQualType NewDeducedType = Context.getCanonicalFunctionResultType( Added: cfe/trunk/test/SemaCXX/typo-correction-crash.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/typo-correction-crash.cpp?rev=259820&view=auto ============================================================================== --- cfe/trunk/test/SemaCXX/typo-correction-crash.cpp (added) +++ cfe/trunk/test/SemaCXX/typo-correction-crash.cpp Thu Feb 4 14:05:40 2016 @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s +auto check1() { + return 1; + return s; // expected-error {{use of undeclared identifier 's'}} +} + +int test = 11; // expected-note {{'test' declared here}} +auto check2() { + return "s"; + return tes; // expected-error {{use of undeclared identifier 'tes'; did you mean 'test'?}} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits