[all-commits] [llvm/llvm-project] c92f50: Correct the behavior of va_arg checking in C++
Aaron Ballman via All-commits
all-commits at lists.llvm.org
Wed Jun 9 04:18:57 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: c92f505346b80fd053ef191bbc66810c9d564b0c
https://github.com/llvm/llvm-project/commit/c92f505346b80fd053ef191bbc66810c9d564b0c
Author: Aaron Ballman <aaron at aaronballman.com>
Date: 2021-06-09 (Wed, 09 Jun 2021)
Changed paths:
M clang/lib/Sema/SemaExpr.cpp
M clang/test/SemaCXX/varargs.cpp
Log Message:
-----------
Correct the behavior of va_arg checking in C++
Clang checks whether the type given to va_arg will automatically cause
undefined behavior, but this check was issuing false positives for
enumerations in C++. The issue turned out to be because
typesAreCompatible() in C++ checks whether the types are *the same*, so
this uses custom logic if the type compatibility check fails.
This issue was found by a user on code like:
typedef enum {
CURLINFO_NONE,
CURLINFO_EFFECTIVE_URL,
CURLINFO_LASTONE = 60
} CURLINFO;
...
__builtin_va_arg(list, CURLINFO); // false positive warning
Given that C++ defers to C for the rules around va_arg, the behavior
should be the same in both C and C++ and not diagnose because int and
CURLINFO are "compatible enough" types for va_arg.
More information about the All-commits
mailing list