Skip to content

Commit 772324f

Browse files
author
Dave Bartolomeo
committed
C++: Add comment with IR for dynamic init of static var
1 parent 709757f commit 772324f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedDeclarationEntry.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ class TranslatedAutoVariableDeclarationEntry extends TranslatedLocalVariableDecl
8484
* initialized, and if not, invokes the initializer and sets the dynamic initialization flag for the
8585
* variable. The actual initialization code is handled in
8686
* `TranslatedStaticLocalVariableInitialization`, which is a child of this element.
87+
*
88+
* The generated code to do the initialization only once is:
89+
* ```
90+
* Block 1
91+
* r1225_1(glval<bool>) = VariableAddress[c#init] :
92+
* r1225_2(bool) = Load : &:r1225_1, ~mu1222_4
93+
* v1225_3(void) = ConditionalBranch : r1225_2
94+
* False -> Block 2
95+
* True -> Block 3
96+
*
97+
* Block 2
98+
* r1225_4(glval<int>) = VariableAddress[c] :
99+
* <actual initialization of `c`>
100+
* r1225_8(bool) = Constant[1] :
101+
* mu1225_9(bool) = Store : &:r1225_1, r1225_8
102+
* Goto -> Block 3
103+
*
104+
* Block 3
105+
* ```
106+
*
107+
* Note that the flag variable, `c#init`, is assumed to be zero-initialized at program startup, just
108+
* like any other variable with static storage duration.
87109
*/
88110
class TranslatedStaticLocalVariableDeclarationEntry extends TranslatedDeclarationEntry {
89111
StaticLocalVariable var;

0 commit comments

Comments
 (0)