Skip to content

[Clang] Add "extend lifetime" flags and release note #110000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,20 @@ New Compiler Flags
only for thread-local variables, and none (which corresponds to the
existing ``-fno-c++-static-destructors`` flag) skips all static
destructors registration.
- The ``-fextend-variable-liveness`` flag has been added to allow for improved
debugging of optimized code. Using ``-fextend-variable-liveness`` will cause
Clang to generate code that tries to preserve the liveness of source variables
through optimizations, meaning that variables will typically be visible in a
debugger more often. The flag has two levels: ``-fextend-variable-liveness``,
or ``-fextend-variable-liveness=all``, extendes the liveness of all user
variables and the ``this`` pointer. Alternatively
``-fextend-variable-liveness=this`` has the same behaviour but applies only to
the ``this`` variable in C++ class member functions, meaning its effect is a
strict subset of ``-fextend-variable-liveness``. Note that this flag modifies
the results of optimizations that Clang performs, which will result in reduced
performance in generated code; however, this feature will not extend the
liveness of some variables in cases where doing so would likely have a severe
impact on generated code performance.

Deprecated Compiler Flags
-------------------------
Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ CODEGENOPT(EnableTLSDESC, 1, 0)
/// Bit size of immediate TLS offsets (0 == use the default).
VALUE_CODEGENOPT(TLSSize, 8, 0)

/// The types of variables that we will extend the live ranges of.
ENUM_CODEGENOPT(ExtendVariableLiveness, ExtendVariableLivenessKind, 2, ExtendVariableLivenessKind::None)

/// The default stack protector guard offset to use.
VALUE_CODEGENOPT(StackProtectorGuardOffset, 32, INT_MAX)

Expand Down
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
Embed_Marker // Embed a marker as a placeholder for bitcode.
};

enum class ExtendVariableLivenessKind {
None,
This,
All,
};

enum InlineAsmDialectKind {
IAD_ATT,
IAD_Intel,
Expand Down
12 changes: 12 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -4298,6 +4298,18 @@ def stack_usage_file : Separate<["-"], "stack-usage-file">,
Visibility<[CC1Option]>,
HelpText<"Filename (or -) to write stack usage output to">,
MarshallingInfoString<CodeGenOpts<"StackUsageOutput">>;
def fextend_variable_liveness_EQ : Joined<["-"], "fextend-variable-liveness=">,
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Extend the liveness of user variables through optimizations to "
"prevent stale or optimized-out variable values when debugging."
Values<"all,this,none">,
NormalizedValues<["All", "This", "None"]>,
NormalizedValuesScope<"CodeGenOptions::ExtendVariableLivenessKind">,
MarshallingInfoEnum<CodeGenOpts<"ExtendVariableLiveness">, "None">;
def fextend_variable_liveness : Flag<["-"], "fextend-variable-liveness">,
Visibility<[ClangOption, CC1Option]>,
Alias<fextend_variable_liveness_EQ>, AliasArgs<["all"]>,
HelpText<"Alias for -fextend-variable-liveness=all.">;

defm unique_basic_block_section_names : BoolFOption<"unique-basic-block-section-names",
CodeGenOpts<"UniqueBasicBlockSectionNames">, DefaultFalse,
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7654,6 +7654,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
CmdArgs.push_back("-fretain-comments-from-system-headers");

Args.AddLastArg(CmdArgs, options::OPT_fextend_variable_liveness_EQ);

// Forward -fcomment-block-commands to -cc1.
Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
// Forward -fparse-all-comments to -cc1.
Expand Down
14 changes: 14 additions & 0 deletions clang/test/Driver/extend-variable-liveness.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Tests that -fextend-variable-liveness and its aliases are correctly passed
// by the driver.

// RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,DEFAULT
// RUN: %clang -fextend-variable-liveness=none -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NONE
// RUN: %clang -fextend-variable-liveness=this -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,THIS
// RUN: %clang -fextend-variable-liveness=all -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL
// RUN: %clang -fextend-variable-liveness -### -c %s 2>&1 | FileCheck %s --check-prefixes=CHECK,ALL

// CHECK: "-cc1"
// DEFAULT-NOT: -fextend-variable-liveness
// NONE-SAME: "-fextend-variable-liveness=none"
// THIS-SAME: "-fextend-variable-liveness=this"
// ALL-SAME: "-fextend-variable-liveness=all"
Loading