Author: erichkeane Date: Fri Jan 4 07:24:06 2019 New Revision: 350398 URL: http://llvm.org/viewvc/llvm-project?rev=350398&view=rev Log: Prevent unreachable when checking invalid multiversion decls.
CPUSpecifc/CPUDispatch call resolution assumed that all declarations that would be passed are valid, however this was an invalid assumption. This patch deals with those situations by making the valid version take priority. Note that the checked ordering is arbitrary, since both are replaced by calls to the resolver later. Change-Id: I7ff2ec88c55a721d51bc1f39ea1a1fe242b4e45f Modified: cfe/trunk/lib/Sema/SemaOverload.cpp cfe/trunk/test/Sema/attr-cpuspecific.c Modified: cfe/trunk/lib/Sema/SemaOverload.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=350398&r1=350397&r2=350398&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) +++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Jan 4 07:24:06 2019 @@ -9023,6 +9023,11 @@ static bool isBetterMultiversionCandidat !Cand2.Function->isMultiVersion()) return false; + // If Cand1 is invalid, it cannot be a better match, if Cand2 is invalid, this + // is obviously better. + if (Cand1.Function->isInvalidDecl()) return false; + if (Cand2.Function->isInvalidDecl()) return true; + // If this is a cpu_dispatch/cpu_specific multiversion situation, prefer // cpu_dispatch, else arbitrarily based on the identifiers. bool Cand1CPUDisp = Cand1.Function->hasAttr<CPUDispatchAttr>(); Modified: cfe/trunk/test/Sema/attr-cpuspecific.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-cpuspecific.c?rev=350398&r1=350397&r2=350398&view=diff ============================================================================== --- cfe/trunk/test/Sema/attr-cpuspecific.c (original) +++ cfe/trunk/test/Sema/attr-cpuspecific.c Fri Jan 4 07:24:06 2019 @@ -92,3 +92,15 @@ __vectorcall int __attribute__((cpu_spec int __attribute__((cpu_dispatch(atom))) disp_with_body(void) { return 5; } + +// expected-error@+1 {{invalid option 'INVALID'}} +int __attribute__((cpu_specific(INVALID))) called_invalid_value(void){ return 1;} +// expected-warning@+3 {{attribute declaration must precede definition}} +// expected-note@-2 2 {{previous definition is here}} +// expected-error@+1 {{redefinition of}} +int __attribute__((cpu_specific(pentium_iii))) called_invalid_value(void){ return 2;} +int __attribute__((cpu_specific(pentium_4))) called_invalid_value(void){ return 3;} + +int use3(void) { + return called_invalid_value(); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits