diff --git a/src/libdredd/src/mutate_visitor.cc b/src/libdredd/src/mutate_visitor.cc index 3413e3a9..5adb7891 100644 --- a/src/libdredd/src/mutate_visitor.cc +++ b/src/libdredd/src/mutate_visitor.cc @@ -18,6 +18,7 @@ #include #include +#include "clang/AST/Attrs.inc" #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" #include "clang/AST/DeclCXX.h" @@ -123,9 +124,10 @@ bool MutateVisitor::TraverseDecl(clang::Decl* decl) { } } if (const auto* var_decl = llvm::dyn_cast(decl)) { - if (var_decl->isConstexpr()) { + if (var_decl->isConstexpr() || var_decl->hasAttr()) { // Because Dredd's mutations occur dynamically, they cannot be applied to - // C++ constexprs, which require compile-time evaluation. + // C++ constexprs or variables that require constant initialization as + // these both require compile-time evaluation. return true; } if (!compiler_instance_->getLangOpts().CPlusPlus && diff --git a/test/single_file/const_init.cc b/test/single_file/const_init.cc new file mode 100644 index 00000000..6934836b --- /dev/null +++ b/test/single_file/const_init.cc @@ -0,0 +1,3 @@ +int main() { + [[clang::require_constant_initialization]] static int x = 0; +} diff --git a/test/single_file/const_init.cc.expected b/test/single_file/const_init.cc.expected new file mode 100644 index 00000000..6934836b --- /dev/null +++ b/test/single_file/const_init.cc.expected @@ -0,0 +1,3 @@ +int main() { + [[clang::require_constant_initialization]] static int x = 0; +} diff --git a/test/single_file/const_init.cc.noopt.expected b/test/single_file/const_init.cc.noopt.expected new file mode 100644 index 00000000..6934836b --- /dev/null +++ b/test/single_file/const_init.cc.noopt.expected @@ -0,0 +1,3 @@ +int main() { + [[clang::require_constant_initialization]] static int x = 0; +}