[all-commits] [llvm/llvm-project] b9d623: generate a name of an unnamed global variable for ...

Vyacheslav Levytskyy via All-commits all-commits at lists.llvm.org
Tue Jan 30 09:10:05 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b9d623105d51f5fc2d120c862b4e2bbff310f728
      https://github.com/llvm/llvm-project/commit/b9d623105d51f5fc2d120c862b4e2bbff310f728
  Author: Vyacheslav Levytskyy <89994100+VyacheslavLevytskyy at users.noreply.github.com>
  Date:   2024-01-30 (Tue, 30 Jan 2024)

  Changed paths:
    M llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
    A llvm/test/CodeGen/SPIRV/unnamed-global.ll

  Log Message:
  -----------
  generate a name of an unnamed global variable for Instruction Selection (#78293)

The goal of this PR is to fix the issue of global unnamed variables
causing SPIR-V Backend code generation to crash:
https://github.com/llvm/llvm-project/issues/78278

The reason for the crash is that GlobalValue's getGlobalIdentifier()
would fail for unnamed global variable when trying to access the first
character of the name (see lib/IR/Globals.cpp:150). This leads to assert
in Debug and undefined behaviour in Release builds.

The proposed fix generates a name of an unnamed global variable as
__unnamed_<unsigned number>, in a style of similar existing LLVM
implementation (see lib/IR/Mangler.cpp:131). A new class member variable
is added into `SPIRVInstructionSelector` class to keep track of the
number we give to anonymous global values to generate the same name
every time when this is needed.

The patch adds a new LIT test with the smallest implementation of
reproducer ll code.




More information about the All-commits mailing list