[clang] c0703ea - [clang][dataflow] Emit an error if source code is not compiled as C++. (#65301)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 6 01:02:26 PDT 2023
Author: martinboehme
Date: 2023-09-06T10:02:21+02:00
New Revision: c0703eaec1df4cde861f15e244507ef79f2d3d82
URL: https://github.com/llvm/llvm-project/commit/c0703eaec1df4cde861f15e244507ef79f2d3d82
DIFF: https://github.com/llvm/llvm-project/commit/c0703eaec1df4cde861f15e244507ef79f2d3d82.diff
LOG: [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++.
Added:
Modified:
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index 7f9bc31bd41f2dd..004b7711a869d17 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -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;
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ff3618e999f004a..28d062196cb07bf 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -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() {
More information about the cfe-commits
mailing list