diff --git a/lib/DxcSupport/HLSLOptions.cpp b/lib/DxcSupport/HLSLOptions.cpp index 7eca30277..717bb15b6 100644 --- a/lib/DxcSupport/HLSLOptions.cpp +++ b/lib/DxcSupport/HLSLOptions.cpp @@ -779,9 +779,8 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude, opts.ResMayAlias = Args.hasFlag(OPT_res_may_alias_, OPT_INVALID, opts.ResMayAlias); opts.ForceZeroStoreLifetimes = Args.hasFlag(OPT_force_zero_store_lifetimes, OPT_INVALID, false); // Lifetime markers on by default in 6.6 unless disabled explicitly - opts.EnableLifetimeMarkers = Args.hasFlag(OPT_enable_lifetime_markers, OPT_INVALID, - DXIL::CompareVersions(Major, Minor, 6, 6) >= 0) && - !Args.hasFlag(OPT_disable_lifetime_markers, OPT_INVALID, false); + opts.EnableLifetimeMarkers = Args.hasFlag(OPT_enable_lifetime_markers, OPT_disable_lifetime_markers, + DXIL::CompareVersions(Major, Minor, 6, 6) >= 0); opts.ForceDisableLocTracking = Args.hasFlag(OPT_fdisable_loc_tracking, OPT_INVALID, false); opts.NewInlining = diff --git a/tools/clang/test/HLSLFileCheck/hlsl/lifetimes/lifetimes-flag.hlsl b/tools/clang/test/HLSLFileCheck/hlsl/lifetimes/lifetimes-flag.hlsl new file mode 100644 index 000000000..644d1265e --- /dev/null +++ b/tools/clang/test/HLSLFileCheck/hlsl/lifetimes/lifetimes-flag.hlsl @@ -0,0 +1,37 @@ +// This test checks that the lifetime markers flag works correctly when +// multiple instances are given on the command line. +// +// The shader here is not important except that it triggers the insertion +// of lifetime markers when they are enabled. + +// Default value is enabled for 6.6. +// RUN: %dxc /Tvs_6_6 %s | FileCheck %s -check-prefix=ENABLE + +// Explicitly enabling the flag should enable lifetime markers. +// RUN: %dxc /Tvs_6_6 %s -enable-lifetime-markers | FileCheck %s -check-prefix=ENABLE + +// Explicitly disabling the flag should disable lifetime markers. +// RUN: %dxc /Tvs_6_6 %s -disable-lifetime-markers | FileCheck %s -check-prefix=DISABLE + +// When both enable and disable flags are given the last occurence should win. +// RUN: %dxc /Tvs_6_6 %s -enable-lifetime-markers -disable-lifetime-markers | FileCheck %s -check-prefix=DISABLE +// RUN: %dxc /Tvs_6_6 %s -disable-lifetime-markers -enable-lifetime-markers | FileCheck %s -check-prefix=ENABLE + +// ENABLE: define void @main() +// ENABLE: call void @llvm.lifetime.start + +// DISABLE: define void @main() +// DISABLE-NOT: call void @llvm.lifetime.start + +void foo() {}; + +[RootSignature("DescriptorTable(UAV(u0, numDescriptors=10))")] +float main(int N : A, float X : X) : Z { + float Arr[64]; + + foo(); + Arr[N] = 0; + foo(); + + return Arr[X]; +} \ No newline at end of file