<div dir="ltr">On Tue, Sep 26, 2017 at 11:10 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Shouldn't you only loosen the check for things targeting the Windows SDK? GNU platforms shouldn't need this.</div></blockquote><div><br></div><div>That code path only actually happens for MS mode. `__va_start` is marked as `ALL_MS_LANGUAGES`. I suppoes that it would be better to rename the function to `SemaBuiltinVAStartARMMicrosoft`. Actually, I like this much better, I'll rename it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Tue, Sep 26, 2017 at 10:44 AM, Saleem Abdulrasool via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: compnerd<br>
Date: Tue Sep 26 10:44:10 2017<br>
New Revision: 314226<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=314226&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=314226&view=rev</a><br>
Log:<br>
Sema: Windows/ARM __va_start is not const correct<br>
<br>
The `__va_start` intrinsic for Windows ARM does not account for const<br>
correctness when performing a check. All local qualifiers are ignored<br>
when validating the invocation. This was exposed by building the swift<br>
stdlib against the Windows 10586 SDK for ARM. Simply expand out the<br>
check for the two parameters and ignore the qualifiers for the check.<br>
<br>
Modified:<br>
cfe/trunk/lib/Sema/SemaCheckin<wbr>g.cpp<br>
cfe/trunk/test/SemaCXX/microso<wbr>ft-varargs.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaCheckin<wbr>g.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=314226&r1=314225&r2=314226&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Sema/SemaC<wbr>hecking.cpp?rev=314226&r1=<wbr>314225&r2=314226&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/SemaCheckin<wbr>g.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaCheckin<wbr>g.cpp Tue Sep 26 10:44:10 2017<br>
@@ -3943,23 +3943,33 @@ bool Sema::SemaBuiltinVAStartARM(Ca<wbr>llExp<br>
if (checkVAStartIsInVariadicFunct<wbr>ion(*this, Func))<br>
return true;<br>
<br>
- const struct {<br>
- unsigned ArgNo;<br>
- QualType Type;<br>
- } ArgumentTypes[] = {<br>
- { 1, Context.getPointerType(Context<wbr>.CharTy.withConst()) },<br>
- { 2, Context.getSizeType() },<br>
- };<br>
-<br>
- for (const auto &AT : ArgumentTypes) {<br>
- const Expr *Arg = Call->getArg(AT.ArgNo)->Ignore<wbr>Parens();<br>
- if (Arg->getType().getCanonicalTy<wbr>pe() == AT.Type.getCanonicalType())<br>
- continue;<br>
- Diag(Arg->getLocStart(), diag::err_typecheck_convert_in<wbr>compatible)<br>
- << Arg->getType() << AT.Type << 1 /* different class */<br>
- << 0 /* qualifier difference */ << 3 /* parameter mismatch */<br>
- << AT.ArgNo + 1 << Arg->getType() << AT.Type;<br>
- }<br>
+ // __va_start on Windows does not validate the parameter qualifiers<br>
+<br>
+ const Expr *Arg1 = Call->getArg(1)->IgnoreParens(<wbr>);<br>
+ const Type *Arg1Ty = Arg1->getType().getCanonicalTy<wbr>pe().getTypePtr();<br>
+<br>
+ const Expr *Arg2 = Call->getArg(2)->IgnoreParens(<wbr>);<br>
+ const Type *Arg2Ty = Arg2->getType().getCanonicalTy<wbr>pe().getTypePtr();<br>
+<br>
+ const QualType &ConstCharPtrTy =<br>
+ Context.getPointerType(Context<wbr>.CharTy.withConst());<br>
+ if (!Arg1Ty->isPointerType() ||<br>
+ Arg1Ty->getPointeeType().witho<wbr>utLocalFastQualifiers() != Context.CharTy)<br>
+ Diag(Arg1->getLocStart(), diag::err_typecheck_convert_in<wbr>compatible)<br>
+ << Arg1->getType() << ConstCharPtrTy<br>
+ << 1 /* different class */<br>
+ << 0 /* qualifier difference */<br>
+ << 3 /* parameter mismatch */<br>
+ << 2 << Arg1->getType() << ConstCharPtrTy;<br>
+<br>
+ const QualType SizeTy = Context.getSizeType();<br>
+ if (Arg2Ty->getCanonicalTypeInter<wbr>nal().withoutLocalFastQualifie<wbr>rs() != SizeTy)<br>
+ Diag(Arg2->getLocStart(), diag::err_typecheck_convert_in<wbr>compatible)<br>
+ << Arg2->getType() << SizeTy<br>
+ << 1 /* different class */<br>
+ << 0 /* qualifier difference */<br>
+ << 3 /* parameter mismatch */<br>
+ << 3 << Arg2->getType() << SizeTy;<br>
<br>
return false;<br>
}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/microso<wbr>ft-varargs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/microsoft-varargs.cpp?rev=314226&r1=314225&r2=314226&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/SemaCXX/<wbr>microsoft-varargs.cpp?rev=<wbr>314226&r1=314225&r2=314226&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/microso<wbr>ft-varargs.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/microso<wbr>ft-varargs.cpp Tue Sep 26 10:44:10 2017<br>
@@ -20,3 +20,8 @@ int builtin(int i, ...) {<br>
return __builtin_va_arg(ap, int);<br>
}<br>
<br>
+void test___va_start_ignore_const(c<wbr>onst char *format, ...) {<br>
+ va_list args;<br>
+ ((void)(__va_start(&args, (&const_cast<char &>(reinterpret_cast<const volatile char &>(format))), ((sizeof(format) + 4 - 1) & ~(4 - 1)), (&const_cast<char &>(reinterpret_cast<const volatile char &>(format))))));<br>
+}<br>
+<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>