KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.9k stars 816 forks source link

Sanitize debug source location tracking for implicit branch and return #3645

Open qingyuanzNV opened 4 days ago

qingyuanzNV commented 4 days ago

This patch improves the debug line generation for implicit branch/return instructions. "IMPLICIT" means that a branch/return instruction is generated by the compiler to compose a structural construct instead of being translated from a program statement. Therefore:

  1. All branches without an explicit "break/continue" are implicit.
  2. All conditional branches are implicit.
  3. All returns without an explicit "return" are implicit.

For implicit branch instruction, we always don't give it a debug location. Instead, we attach it to the whatever preceding instruction in the block. Typically, they should have the line number of the selection expression or the last statement in if/else body. Sometimes, we get empty if/else body. In this case, no debug location will be generated. (Ideally, we could have it point to '}' of the empty block. But glslang will set the statement node to nullptr instead of creating an empty aggregate) For implicit return instruction, we always give it a debug location pointing to the closing '}' of the function body.

Additionally, this patch fix a bug where Phi instruction in the selection statement doesn't get a debug location.