<div dir="ltr">Shouldn't you only loosen the check for things targeting the Windows SDK? GNU platforms shouldn't need this.</div><div class="gmail_extra"><br><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-<wbr>project?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/<wbr>SemaChecking.cpp<br>
    cfe/trunk/test/SemaCXX/<wbr>microsoft-varargs.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>SemaChecking.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-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaChecking.cpp?rev=314226&<wbr>r1=314225&r2=314226&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaChecking.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>SemaChecking.cpp Tue Sep 26 10:44:10 2017<br>
@@ -3943,23 +3943,33 @@ bool Sema::SemaBuiltinVAStartARM(<wbr>CallExp<br>
   if (<wbr>checkVAStartIsInVariadicFuncti<wbr>on(*this, Func))<br>
     return true;<br>
<br>
-  const struct {<br>
-    unsigned ArgNo;<br>
-    QualType Type;<br>
-  } ArgumentTypes[] = {<br>
-    { 1, Context.getPointerType(<wbr>Context.CharTy.withConst()) },<br>
-    { 2, Context.getSizeType() },<br>
-  };<br>
-<br>
-  for (const auto &AT : ArgumentTypes) {<br>
-    const Expr *Arg = Call->getArg(AT.ArgNo)-><wbr>IgnoreParens();<br>
-    if (Arg->getType().<wbr>getCanonicalType() == AT.Type.getCanonicalType())<br>
-      continue;<br>
-    Diag(Arg->getLocStart(), diag::err_typecheck_convert_<wbr>incompatible)<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().<wbr>getCanonicalType().getTypePtr(<wbr>);<br>
+<br>
+  const Expr *Arg2 = Call->getArg(2)->IgnoreParens(<wbr>);<br>
+  const Type *Arg2Ty = Arg2->getType().<wbr>getCanonicalType().getTypePtr(<wbr>);<br>
+<br>
+  const QualType &ConstCharPtrTy =<br>
+      Context.getPointerType(<wbr>Context.CharTy.withConst());<br>
+  if (!Arg1Ty->isPointerType() ||<br>
+      Arg1Ty->getPointeeType().<wbr>withoutLocalFastQualifiers() != Context.CharTy)<br>
+    Diag(Arg1->getLocStart(), diag::err_typecheck_convert_<wbr>incompatible)<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-><wbr>getCanonicalTypeInternal().<wbr>withoutLocalFastQualifiers() != SizeTy)<br>
+    Diag(Arg2->getLocStart(), diag::err_typecheck_convert_<wbr>incompatible)<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/<wbr>microsoft-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-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/microsoft-varargs.cpp?<wbr>rev=314226&r1=314225&r2=<wbr>314226&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/<wbr>microsoft-varargs.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/<wbr>microsoft-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(<wbr>const 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">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>