kda created this revision. kda added a reviewer: vitalybuka. Herald added a subscriber: dang. kda requested review of this revision. Herald added projects: clang, Sanitizers. Herald added subscribers: Sanitizers, cfe-commits.
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 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D117293 Files: clang/include/clang/Driver/Options.td clang/test/CodeGen/msan-param-retval.c compiler-rt/test/msan/noundef_analysis.cpp Index: compiler-rt/test/msan/noundef_analysis.cpp =================================================================== --- compiler-rt/test/msan/noundef_analysis.cpp +++ 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; Index: clang/test/CodeGen/msan-param-retval.c =================================================================== --- clang/test/CodeGen/msan-param-retval.c +++ 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 Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1670,13 +1670,12 @@ 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 @@ 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">>;
Index: compiler-rt/test/msan/noundef_analysis.cpp =================================================================== --- compiler-rt/test/msan/noundef_analysis.cpp +++ 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; Index: clang/test/CodeGen/msan-param-retval.c =================================================================== --- clang/test/CodeGen/msan-param-retval.c +++ 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 Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1670,13 +1670,12 @@ 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 @@ 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">>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits