[LLVMdev] Large constants in patchpoints

Sanjoy Das sanjoy at playingwithpointers.com
Fri Oct 31 11:20:28 PDT 2014

Currently llvm crashes on following code, run through llc:

declare void @llvm.experimental.stackmap(i64, i32, ...)

define void @foo() {
  tail call void (i64, i32, ...)* @llvm.experimental.stackmap(i64 0,
i32 0, i64 9223372036854775807)
  ret void

The issue is that 9223372036854775807 (decimal for 0x7fffffffffffffff)
is the "empty key" for an int64_t, and in
StackMaps::recordStackMapOpers we crash when we try to insert this as
a key into ConstPool.  The this happens if we change the constant to
be the tombstone.

Two potential fixes I can think of:

 1. have some special logic to remember the offsets for the tombstone
    and empty i64 constants.  This can easily be tracked using two
    "Optional<int>" fields.

 2. change ConstantPool to be use a std::map instead of a
    llvm::DenseMap as the map in the MapVector.

An aside: the same function has this check "((I->Offset +
(int64_t(1)<<31)) >> 32)" -- won't this cause a signed overflow (and
hence UB) if I->Offset is negative?

-- Sanjoy

More information about the llvm-dev mailing list