svn commit: r304960 - projects/clang390-import/contrib/llvm/tools/clang/lib/Sema

Dimitry Andric dim at FreeBSD.org
Sun Aug 28 19:28:02 UTC 2016


Author: dim
Date: Sun Aug 28 19:28:00 2016
New Revision: 304960
URL: https://svnweb.freebsd.org/changeset/base/304960

Log:
  Tentatively apply https://reviews.llvm.org/D23921, to get rid of false
  positive diagnostics from -Wvarargs about enum parameters, e.g.:
  
  cddl/contrib/opensolaris/lib/libnvpair/libnvpair.c:388:15: error: passing an object that undergoes default argument promotion to 'va_start' has undefined behavior
        [-Werror,-Wvarargs]
          va_start(ap, which);
                       ^
  cddl/contrib/opensolaris/lib/libnvpair/libnvpair.c:382:66: note: parameter of type 'enum nvlist_prtctl_fmt' is declared here
  nvlist_prtctl_dofmt(nvlist_prtctl_t pctl, enum nvlist_prtctl_fmt which, ...)
                                                                   ^

Modified:
  projects/clang390-import/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp

Modified: projects/clang390-import/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp
==============================================================================
--- projects/clang390-import/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp	Sun Aug 28 18:10:29 2016	(r304959)
+++ projects/clang390-import/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp	Sun Aug 28 19:28:00 2016	(r304960)
@@ -3189,8 +3189,17 @@ bool Sema::SemaBuiltinVAStartImpl(CallEx
     Diag(TheCall->getArg(1)->getLocStart(),
          diag::warn_second_arg_of_va_start_not_last_named_param);
   else if (IsCRegister || Type->isReferenceType() ||
-           Type->isPromotableIntegerType() ||
-           Type->isSpecificBuiltinType(BuiltinType::Float)) {
+           Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
+             // Promotable integers are UB, but enumerations need a bit of
+             // extra checking to see what their promotable type actually is.
+             if (!Type->isPromotableIntegerType())
+               return false;
+             if (!Type->isEnumeralType())
+               return true;
+             const EnumDecl *ED = Type->getAs<EnumType>()->getDecl();
+             return !(ED &&
+                      Context.typesAreCompatible(ED->getPromotionType(), Type));
+           }()) {
     unsigned Reason = 0;
     if (Type->isReferenceType())  Reason = 1;
     else if (IsCRegister)         Reason = 2;


More information about the svn-src-projects mailing list