Skip to content

[MIPS] Compiler crash when using -O3 #134916

@hpoussin

Description

@hpoussin

Using clang version 20.1.2

clang -target "mipsel-w64-windows-gnu" -c test.cpp -O3

typedef unsigned int size_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned int uintptr_t;
typedef signed char int8_t;
typedef short int16_t;
typedef int int32_t;
typedef long long int64_t;

size_t readULEB128(const uint8_t **data);

// read a pointer encoded value and advance pointer
static uintptr_t readEncodedPointer(const uint8_t **data, uint8_t encoding) {
  const uint8_t *p = *data;
  uintptr_t result = 0;

  // first get value
  switch (encoding & 0x0F) {
  case 0x01:
    result = readULEB128(&p);
    break;
  case 0x0A:
    result = *((const int16_t *)p);
    p += sizeof(int16_t);
    break;
  case 0x0B:
    result = *((const int32_t *)p);
    p += sizeof(int32_t);
    break;
  case 0x0C:
    result = *((const int64_t *)p);
    p += sizeof(int64_t);
    break;
  default:
    // not supported
    return 0;
  }

  *data = p;
  return result;
}

int __gcc_personality_v0(const uint8_t* lsda)
{
  uint8_t callSiteEncoding = *lsda++;
  const uint8_t *p = 0;
  while (1) {
    uintptr_t start = readEncodedPointer(&p, callSiteEncoding);
    size_t length = readEncodedPointer(&p, callSiteEncoding);
    size_t landingPad = readEncodedPointer(&p, callSiteEncoding);
    readULEB128(&p); // action value not used for C code
  }

  // No landing pad found, continue unwinding.
  return 0;
}

gives

fatal error: error in backend: Not supported instr: <MCInst 45 <MCOperand Imm:0>>

Possible workaround: add -O0

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend:MIPScrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions