CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

Assertion when taking address of label #141

Closed arichardson closed 4 years ago

arichardson commented 7 years ago

Happens when compiling 2004-03-15-IndirectGoto.c from llvm-test-suite for CheriABI

lib/IR/Constants.cpp:1431: static llvm::Constant *llvm::ConstantExpr::getCast(unsigned int, llvm::Constant *, llvm::Type *, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && "Invalid constantexpr cast!"' failed.

reduced test case:

// RUN: %clang_cc1 -triple cheri-unknown-freebsd12 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name 2004-03-15-IndirectGoto.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu cheri -target-feature +soft-float -target-abi purecap -msoft-float -mfloat-abi soft -mllvm -mxgot -mllvm -mips-ssection-threshold=0 -dwarf-column-info -sys-header-deps -D NDEBUG -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gnustep -fdiagnostics-show-option -cheri-linker -x c -o - -emit-llvm -w %s | FileCheck %s
int a() {
  &&b;
b:;
}
arichardson commented 7 years ago

Full source file is:

#include <stdio.h>
int main() {
  static const void *L[] = {&&L1, &&L2, &&L3, &&L4, 0 };
  unsigned i = 0;
  printf("A\n");
L1:
  printf("B\n");
L2:
  printf("C\n");
L3:
  printf("D\n");
  goto *L[i++];
L4: 
  printf("E\n");
  return 0;
}
arichardson commented 4 years ago

Fixed a long time ago.