| 1 |
/* |
| 2 |
SPDX-FileCopyrightText: 2018 Sergio Martins <[email protected]> |
| 3 |
|
| 4 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "qstring-varargs.h" |
| 8 |
#include "StringUtils.h" |
| 9 |
|
| 10 |
#include <clang/AST/Decl.h> |
| 11 |
#include <clang/AST/DeclCXX.h> |
| 12 |
#include <clang/AST/Expr.h> |
| 13 |
#include <clang/AST/OperationKinds.h> |
| 14 |
#include <clang/AST/Stmt.h> |
| 15 |
#include <clang/AST/Type.h> |
| 16 |
#include <clang/Basic/LLVM.h> |
| 17 |
#include <llvm/ADT/StringRef.h> |
| 18 |
#include <llvm/Support/Casting.h> |
| 19 |
|
| 20 |
using namespace clang; |
| 21 |
|
| 22 |
void QStringVarargs::VisitStmt(clang::Stmt *stmt) |
| 23 |
{ |
| 24 |
auto *binop = dyn_cast<BinaryOperator>(stmt); |
| 25 |
if (!binop || binop->getOpcode() != BO_Comma) { |
| 26 |
return; |
| 27 |
} |
| 28 |
|
| 29 |
auto *callexpr = dyn_cast<CallExpr>(binop->getLHS()); |
| 30 |
if (!callexpr) { |
| 31 |
return; |
| 32 |
} |
| 33 |
|
| 34 |
const FunctionDecl *func = callexpr->getDirectCallee(); |
| 35 |
if (!func || clazy::name(func) != "__builtin_trap") { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
QualType qt = binop->getRHS()->getType(); |
| 40 |
const CXXRecordDecl *record = qt->getAsCXXRecordDecl(); |
| 41 |
if (!record) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
StringRef name = clazy::name(record); |
| 46 |
if (name == "QString" || name == "QByteArray") { |
| 47 |
emitWarning(stmt, std::string("Passing ") + name.data() + std::string(" to variadic function")); |
| 48 |
} |
| 49 |
} |