From 0abae3c0fc346a6fc8d4d4afc8b07d94c8aadcb5 Mon Sep 17 00:00:00 2001 From: "Alastair F. Donaldson" Date: Sat, 11 Nov 2023 00:00:46 +0000 Subject: [PATCH] Avoid mutating `noexcept` qualifiers. --- src/libdredd/src/mutate_visitor.cc | 6 ++++++ test/single_file/noexcept.cc | 1 + test/single_file/noexcept.cc.expected | 1 + test/single_file/noexcept.cc.noopt.expected | 1 + 4 files changed, 9 insertions(+) create mode 100644 test/single_file/noexcept.cc create mode 100644 test/single_file/noexcept.cc.expected create mode 100644 test/single_file/noexcept.cc.noopt.expected diff --git a/src/libdredd/src/mutate_visitor.cc b/src/libdredd/src/mutate_visitor.cc index 2d17c575..025cbb3b 100644 --- a/src/libdredd/src/mutate_visitor.cc +++ b/src/libdredd/src/mutate_visitor.cc @@ -158,6 +158,12 @@ bool MutateVisitor::TraverseDecl(clang::Decl* decl) { } bool MutateVisitor::TraverseStmt(clang::Stmt* stmt) { + // Do not mutate under a constant expression, since mutation logic is + // inherently non-constant. + if (stmt != nullptr && llvm::dyn_cast(stmt) != nullptr) { + return true; + } + // Add a node to the mutation tree to capture any mutations beneath this // statement. const PushMutationTreeRAII push_mutation_tree(*this); diff --git a/test/single_file/noexcept.cc b/test/single_file/noexcept.cc new file mode 100644 index 00000000..7847adfb --- /dev/null +++ b/test/single_file/noexcept.cc @@ -0,0 +1 @@ +void foo() noexcept(true); diff --git a/test/single_file/noexcept.cc.expected b/test/single_file/noexcept.cc.expected new file mode 100644 index 00000000..7847adfb --- /dev/null +++ b/test/single_file/noexcept.cc.expected @@ -0,0 +1 @@ +void foo() noexcept(true); diff --git a/test/single_file/noexcept.cc.noopt.expected b/test/single_file/noexcept.cc.noopt.expected new file mode 100644 index 00000000..7847adfb --- /dev/null +++ b/test/single_file/noexcept.cc.noopt.expected @@ -0,0 +1 @@ +void foo() noexcept(true);