[clang] 0f93448 - enable noundef analysis with -fsanitize-memory-param-retval
Kevin Athey via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 14 17:18:33 PST 2022
Author: Kevin Athey
Date: 2022-01-14T17:18:29-08:00
New Revision: 0f93448235fe9727251fad6d170fb7d47a5f44cd
URL: https://github.com/llvm/llvm-project/commit/0f93448235fe9727251fad6d170fb7d47a5f44cd
DIFF: https://github.com/llvm/llvm-project/commit/0f93448235fe9727251fad6d170fb7d47a5f44cd.diff
LOG: enable noundef analysis with -fsanitize-memory-param-retval
Enable noundef analysis (-enable-noundef-analysis) via the -fsanitize-memory-param-retval clang flag.
This completes the work found in:
- https://reviews.llvm.org/D116855
- https://reviews.llvm.org/D116633
Depends on D116633
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D117293
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/test/CodeGen/attr-noundef.cpp
clang/test/CodeGen/indirect-noundef.cpp
clang/test/CodeGen/msan-param-retval.c
compiler-rt/test/msan/noundef_analysis.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ecdeb900e1c0c..0a1b922676284 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1670,13 +1670,12 @@ def sanitize_address_destructor_EQ
NormalizedValues<["None", "Global"]>,
MarshallingInfoEnum<CodeGenOpts<"SanitizeAddressDtor">, "Global">;
defm sanitize_memory_param_retval
- : BoolOption<"f", "sanitize-memory-param-retval",
- CodeGenOpts<"SanitizeMemoryParamRetval">,
- DefaultFalse,
- PosFlag<SetTrue, [CC1Option], "Enable">, NegFlag<SetFalse, [], "Disable">,
- BothFlags<[], " detection of uninitialized parameters and return values">>,
- Group<f_clang_Group>;
-// Note: This flag was introduced when it was necessary to distinguish between
+ : BoolFOption<"sanitize-memory-param-retval",
+ CodeGenOpts<"SanitizeMemoryParamRetval">,
+ DefaultFalse,
+ PosFlag<SetTrue, [CC1Option], "Enable">, NegFlag<SetFalse, [], "Disable">,
+ BothFlags<[], " detection of uninitialized parameters and return values">>;
+//// Note: This flag was introduced when it was necessary to distinguish between
// ABI for correct codegen. This is no longer needed, but the flag is
// not removed since targeting either ABI will behave the same.
// This way we cause no disturbance to existing scripts & code, and if we
@@ -5399,7 +5398,8 @@ defm clear_ast_before_backend : BoolOption<"",
BothFlags<[], " the Clang AST before running backend code generation">>;
def enable_noundef_analysis : Flag<["-"], "enable-noundef-analysis">, Group<f_Group>,
HelpText<"Enable analyzing function argument and return types for mandatory definedness">,
- MarshallingInfoFlag<CodeGenOpts<"EnableNoundefAttrs">>;
+ MarshallingInfoFlag<CodeGenOpts<"EnableNoundefAttrs">>,
+ ImpliedByAnyOf<[fsanitize_memory_param_retval.KeyPath]>;
def discard_value_names : Flag<["-"], "discard-value-names">,
HelpText<"Discard value names in LLVM IR">,
MarshallingInfoFlag<CodeGenOpts<"DiscardValueNames">>;
diff --git a/clang/test/CodeGen/attr-noundef.cpp b/clang/test/CodeGen/attr-noundef.cpp
index 57c1ca00cad6e..9fb2ed9d21c9b 100644
--- a/clang/test/CodeGen/attr-noundef.cpp
+++ b/clang/test/CodeGen/attr-noundef.cpp
@@ -1,5 +1,11 @@
// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple aarch64-gnu-linux -x c++ -S -emit-llvm -fsanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-AARCH
+
+// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -enable-noundef-analysis -fno-sanitize-memory-param-retval %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
+// RUN: %clang -cc1 -triple x86_64-gnu-linux -x c++ -S -emit-llvm -fno-sanitize-memory-param-retval -enable-noundef-analysis %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-INTEL
//************ Passing structs by value
// TODO: No structs may currently be marked noundef
diff --git a/clang/test/CodeGen/indirect-noundef.cpp b/clang/test/CodeGen/indirect-noundef.cpp
index 6eccf8c6fb3a6..53b2f4a1adb64 100644
--- a/clang/test/CodeGen/indirect-noundef.cpp
+++ b/clang/test/CodeGen/indirect-noundef.cpp
@@ -1,4 +1,9 @@
// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fsanitize-memory-param-retval -o - %s | FileCheck %s
+
+// no-sanitize-memory-param-retval does NOT conflict with enable-noundef-analysis
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -fno-sanitize-memory-param-retval -enable-noundef-analysis -o - %s | FileCheck %s
+// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -fno-sanitize-memory-param-retval -o - %s | FileCheck %s
union u1 {
int val;
diff --git a/clang/test/CodeGen/msan-param-retval.c b/clang/test/CodeGen/msan-param-retval.c
index 059531b64ac7e..3f1b803a60ce5 100644
--- a/clang/test/CodeGen/msan-param-retval.c
+++ b/clang/test/CodeGen/msan-param-retval.c
@@ -5,7 +5,7 @@
// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks -o - %s | \
// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER
// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -fsanitize-memory-param-retval -o - %s | \
-// RUN: FileCheck %s --check-prefixes=CLEAN
+// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER
// RUN: %clang -target x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -Xclang -enable-noundef-analysis -fsanitize-memory-param-retval -o - %s | \
// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER
diff --git a/compiler-rt/test/msan/noundef_analysis.cpp b/compiler-rt/test/msan/noundef_analysis.cpp
index d0008648e9f65..542fabcf4c935 100644
--- a/compiler-rt/test/msan/noundef_analysis.cpp
+++ b/compiler-rt/test/msan/noundef_analysis.cpp
@@ -2,6 +2,8 @@
// RUN: FileCheck %s --check-prefix=MISSED --allow-empty < %t.out
// RUN: %clangxx_msan %s -Xclang -enable-noundef-analysis -mllvm -msan-eager-checks=1 -o %t && not %run %t >%t.out 2>&1
// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan %s -fsanitize-memory-param-retval -o %t && not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
struct SimpleStruct {
int md1;
More information about the cfe-commits
mailing list