[clang][dataflow] Emit an error if source code is not compiled as C++. (#65301)

The shape of certain elements of the AST can vary depending on the
langugage.
We currently only support C++.
This commit is contained in:
martinboehme 2023-09-06 10:02:21 +02:00 committed by GitHub
parent be12f26dc0
commit c0703eaec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -84,6 +84,13 @@ ControlFlowContext::build(const Decl &D, Stmt &S, ASTContext &C) {
std::make_error_code(std::errc::invalid_argument),
"Cannot analyze templated declarations");
// The shape of certain elements of the AST can vary depending on the
// language. We currently only support C++.
if (!C.getLangOpts().CPlusPlus)
return llvm::createStringError(
std::make_error_code(std::errc::invalid_argument),
"Can only analyze C++");
CFG::BuildOptions Options;
Options.PruneTriviallyFalseEdges = true;
Options.AddImplicitDtors = true;

View File

@ -70,6 +70,16 @@ const Formula &getFormula(const ValueDecl &D, const Environment &Env) {
return cast<BoolValue>(Env.getValue(D))->formula();
}
TEST(TransferTest, CNotSupported) {
std::string Code = R"(
void target() {}
)";
ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(
Code, [](const auto &, auto &) {}, {BuiltinOptions{}},
LangStandard::lang_c89),
llvm::FailedWithMessage("Can only analyze C++"));
}
TEST(TransferTest, IntVarDeclNotTrackedWhenTransferDisabled) {
std::string Code = R"(
void target() {