Skip to content

Commit 540a1a6

Browse files
authored
[clang-cl] Document behavior difference of strict aliasing in clang-cl vs clang. (#68460)
Add an user note to pass -fstrict-aliasing explicitly for clang-cl to enable TBAA. Also add help text for -f[no-]strict-aliasing.
1 parent 37432c1 commit 540a1a6

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clang/docs/UsersManual.rst

+15
Original file line numberDiff line numberDiff line change
@@ -4383,6 +4383,7 @@ Execute ``clang-cl /?`` to see a list of supported options:
43834383
-fno-sanitize-trap=<value>
43844384
Disable trapping for specified sanitizers
43854385
-fno-standalone-debug Limit debug information produced to reduce size of debug binary
4386+
-fno-strict-aliasing Disable optimizations based on strict aliasing rules (default)
43864387
-fobjc-runtime=<value> Specify the target Objective-C runtime kind and version
43874388
-fprofile-exclude-files=<value>
43884389
Instrument only functions from files where names don't match all the regexes separated by a semi-colon
@@ -4444,6 +4445,7 @@ Execute ``clang-cl /?`` to see a list of supported options:
44444445
behavior. See user manual for available checks
44454446
-fsplit-lto-unit Enables splitting of the LTO unit.
44464447
-fstandalone-debug Emit full debug info for all types used by the program
4448+
-fstrict-aliasing Enable optimizations based on strict aliasing rules
44474449
-fsyntax-only Run the preprocessor, parser and semantic analysis stages
44484450
-fwhole-program-vtables Enables whole-program vtable optimization. Requires -flto
44494451
-gcodeview-ghash Emit type record hashes in a .debug$H section
@@ -4722,3 +4724,16 @@ The Visual C++ Toolset has a slightly more elaborate mechanism for detection.
47224724
The registry information is used to help locate the installation as a final
47234725
fallback. This is only possible for pre-VS2017 installations and is
47244726
considered deprecated.
4727+
4728+
Restrictions and Limitations compared to Clang
4729+
----------------------------------------------
4730+
4731+
Strict Aliasing
4732+
^^^^^^^^^^^^^^^
4733+
4734+
Strict aliasing (TBAA) is always off by default in clang-cl. Whereas in clang,
4735+
strict aliasing is turned on by default for all optimization levels.
4736+
4737+
To enable LLVM optimizations based on strict aliasing rules (e.g., optimizations
4738+
based on type of expressions in C/C++), user will need to explicitly pass
4739+
`-fstrict-aliasing` to clang-cl.

clang/include/clang/Driver/Options.td

+4-2
Original file line numberDiff line numberDiff line change
@@ -3152,7 +3152,8 @@ defm diagnostics_show_line_numbers : BoolFOption<"diagnostics-show-line-numbers"
31523152
def fno_stack_protector : Flag<["-"], "fno-stack-protector">, Group<f_Group>,
31533153
HelpText<"Disable the use of stack protectors">;
31543154
def fno_strict_aliasing : Flag<["-"], "fno-strict-aliasing">, Group<f_Group>,
3155-
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>;
3155+
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
3156+
HelpText<"Disable optimizations based on strict aliasing rules">;
31563157
def fstruct_path_tbaa : Flag<["-"], "fstruct-path-tbaa">, Group<f_Group>;
31573158
def fno_struct_path_tbaa : Flag<["-"], "fno-struct-path-tbaa">, Group<f_Group>;
31583159
def fno_strict_enums : Flag<["-"], "fno-strict-enums">, Group<f_Group>;
@@ -3595,7 +3596,8 @@ def fno_debug_macro : Flag<["-"], "fno-debug-macro">, Group<f_Group>,
35953596
Visibility<[ClangOption, CLOption, DXCOption]>,
35963597
HelpText<"Do not emit macro debug information">;
35973598
def fstrict_aliasing : Flag<["-"], "fstrict-aliasing">, Group<f_Group>,
3598-
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>;
3599+
Flags<[NoXarchOption]>, Visibility<[ClangOption, CLOption, DXCOption]>,
3600+
HelpText<"Enable optimizations based on strict aliasing rules">;
35993601
def fstrict_enums : Flag<["-"], "fstrict-enums">, Group<f_Group>,
36003602
Visibility<[ClangOption, CC1Option]>,
36013603
HelpText<"Enable optimizations based on the strict definition of an enum's "

0 commit comments

Comments
 (0)