diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-10-30 14:21:34 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-30 14:21:34 -0700 |
| commit | 098dd5d87ef73528a14b5478616967f16f73a9ad (patch) | |
| tree | cecb84ae7d3b9c09c3eb239f7f7bdebb2215cc1a /source/slang/ir.cpp | |
| parent | baf06088dff0b961843ad03efd75ff009befec5c (diff) | |
Fix a crash on function-static variables with initializers (#703)
This code path hadn't been used, and it had a crash due to not inserting the basic blocks it created (for initializing the variable) into the parent function. The fix adds a bit more smarts to the `IRBuilder` to help with inserting basic blocks into the flow of a function.
The actual user issue was around `static const` declarations, and it is clear that the code is incorrectly treating a function local `static const` as if it were just `static`. That will need to be fixed in another change.
Diffstat (limited to 'source/slang/ir.cpp')
| -rw-r--r-- | source/slang/ir.cpp | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp index 6e14edc1f..cc3350aef 100644 --- a/source/slang/ir.cpp +++ b/source/slang/ir.cpp @@ -2029,23 +2029,37 @@ namespace Slang getBasicBlockType()); } - IRBlock* IRBuilder::emitBlock() + void IRBuilder::insertBlock(IRBlock* block) { - // Create a block - auto bb = createBlock(); - // If we are emitting into a function // (or another value with code), then // append the block to the function and // set this block as the new parent for // subsequent instructions we insert. + // + // TODO: This should probably insert the block + // after the current "insert into" block if + // there is one. Right now we are always + // adding the block to the end of the list, + // which is technically valid (the ordering + // of blocks doesn't affect the CFG topology), + // but some later passes might assume the ordering + // is significant in representing the intent + // of the original code. + // auto f = getFunc(); if (f) { - f->addBlock(bb); - setInsertInto(bb); + f->addBlock(block); + setInsertInto(block); } - return bb; + } + + IRBlock* IRBuilder::emitBlock() + { + auto block = createBlock(); + insertBlock(block); + return block; } IRParam* IRBuilder::createParam( |
