Skip to content

Commit

Permalink
[CFG] [analyzer] Disable argument construction contexts for variadic …
Browse files Browse the repository at this point in the history
…functions.

The analyzer doesn't make use of them anyway and they seem to have
pretty weird AST from time to time, so let's just skip them for now.

Fixes pr37769.

Differential Revision: https://reviews.llvm.org/D50824

llvm-svn: 340975
  • Loading branch information
haoNoQ committed Aug 29, 2018
1 parent f562fc8 commit 594b541
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions clang/lib/Analysis/CFG.cpp
Expand Up @@ -2421,8 +2421,6 @@ CFGBlock *CFGBuilder::VisitCallExpr(CallExpr *C, AddStmtChoice asc) {
if (!boundType.isNull()) calleeType = boundType;
}

findConstructionContextsForArguments(C);

// If this is a call to a no-return function, this stops the block here.
bool NoReturn = getFunctionExtInfo(*calleeType).getNoReturn();

Expand All @@ -2439,6 +2437,13 @@ CFGBlock *CFGBuilder::VisitCallExpr(CallExpr *C, AddStmtChoice asc) {
bool OmitArguments = false;

if (FunctionDecl *FD = C->getDirectCallee()) {
// TODO: Support construction contexts for variadic function arguments.
// These are a bit problematic and not very useful because passing
// C++ objects as C-style variadic arguments doesn't work in general
// (see [expr.call]).
if (!FD->isVariadic())
findConstructionContextsForArguments(C);

if (FD->isNoReturn() || C->isBuiltinAssumeFalse(*Context))
NoReturn = true;
if (FD->hasAttr<NoThrowAttr>())
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Analysis/cfg-rich-constructors.cpp
Expand Up @@ -1028,3 +1028,18 @@ void testOperators() {
C(1) + C(2);
}
} // namespace operators

namespace variadic_function_arguments {
class C {
public:
C(int);
};

int variadic(...);

// This code is quite exotic, so let's not test the CFG for it,
// but only make sure we don't crash.
void testCrashOnVariadicArgument() {
C c(variadic(0 ? c : 0)); // no-crash
}
} // namespace variadic_function_arguments

0 comments on commit 594b541

Please sign in to comment.