Skip to content

Commit b821974

Browse files
committed
ReleaseNotes: -ftrivial-auto-var-init
llvm-svn: 354660
1 parent 6f2b277 commit b821974

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,37 @@ Major New Features
4141
example, due to renaming a class or namespace).
4242
See the :ref:`UsersManual <profile_remapping>` for details.
4343

44+
- Clang has new options to initialize automatic variables with either a pattern or with zeroes. The default is still that automatic variables are uninitialized. This isn't meant to change the semantics of C and C++. Rather, it's meant to be a last resort when programmers inadvertently have some undefined behavior in their code. These options aim to make undefined behavior hurt less, which security-minded people will be very happy about. Notably, this means that there's no inadvertent information leak when:
45+
46+
* The compiler re-uses stack slots, and a value is used uninitialized.
47+
48+
* The compiler re-uses a register, and a value is used uninitialized.
49+
50+
* Stack structs / arrays / unions with padding are copied.
51+
52+
These options only address stack and register information leaks.
53+
54+
Caveats:
55+
56+
* Variables declared in unreachable code and used later aren't initialized. This affects goto statements, Duff's device, and other objectionable uses of switch statements. This should instead be a hard-error in any serious codebase.
57+
58+
* These options don't affect volatile stack variables.
59+
60+
* Padding isn't fully handled yet.
61+
62+
How to use it on the command line:
63+
64+
* ``-ftrivial-auto-var-init=uninitialized`` (the default)
65+
66+
* ``-ftrivial-auto-var-init=pattern``
67+
68+
* ``-ftrivial-auto-var-init=zero`` ``-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang``
69+
70+
There is also a new attribute to request a variable to not be initialized, mainly to disable initialization of large stack arrays when deemed too expensive:
71+
72+
* ``int dont_initialize_me __attribute((uninitialized));``
73+
74+
4475
Improvements to Clang's diagnostics
4576
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4677

0 commit comments

Comments
 (0)