From: David Majnemer Date: Thu, 26 Feb 2015 00:57:33 +0000 (+0000) Subject: Sema: __assume with side effects shouldn't result in invalid AST nodes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21bc4ac3aee00b5af965c8721e11c18bd48fe931;p=clang Sema: __assume with side effects shouldn't result in invalid AST nodes We'd diagnose an __assume expression which contained a function call. This would result in us wrongly returning ExprError, causing mysterious failures later on. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230597 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index bdaba9a7ce..eb6bffcd48 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2378,7 +2378,7 @@ bool Sema::SemaBuiltinAssume(CallExpr *TheCall) { if (Arg->isInstantiationDependent()) return false; if (Arg->HasSideEffects(Context)) - return Diag(Arg->getLocStart(), diag::warn_assume_side_effects) + Diag(Arg->getLocStart(), diag::warn_assume_side_effects) << Arg->getSourceRange() << cast(TheCall->getCalleeDecl())->getIdentifier(); diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp index 42689d141f..736e69a965 100644 --- a/test/Parser/MicrosoftExtensions.cpp +++ b/test/Parser/MicrosoftExtensions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple i386-mingw32 -std=c++11 -fsyntax-only -Wno-unused-getter-return-value -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing +// RUN: %clang_cc1 %s -triple i386-mingw32 -std=c++14 -fsyntax-only -Wno-unused-getter-return-value -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing /* Microsoft attribute tests */ [repeatable][source_annotation_attribute( Parameter|ReturnValue )] @@ -375,3 +375,19 @@ typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-war typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}} typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}} typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}} + +namespace { +bool f(int); +template +struct A { + constexpr A(T t) { + __assume(f(t)); // expected-warning{{the argument to '__assume' has side effects that will be discarded}} + } + constexpr bool g() { return false; } +}; +constexpr A h() { + A b(0); // expected-note {{in instantiation of member function}} + return b; +} +static_assert(h().g() == false, ""); +}