Is it possible to create a variable that aliases a field in a struct ?

Hi all,

Given assert code in alias detection I’ve opted for a simplification in expressing field address :

target datalayout = “e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64”

%struct._dpowk_16 = type < { [32 x [32 x double]], [32 x [32 x double]], [32 x [32 x i64]] } >

@_dpowk_16 = common global %struct._dpowk_16 zeroinitializer, align 16

@r_d_field = alias [32 x [32 x double]] * getelementptr (%struct._dpowk_16 * @_dpowk_16, i32 0, i32 1)

Now I’ve got following error from opt :

opt -O2 -S gblmod2.ll -o gblmod2.opt.ll

opt: /home/sdeldon/tools/llvm/3.2/llvm-3.2.src/include/llvm/Support/Casting.h:208: typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X = llvm::GlobalValue, Y = llvm::Value*]: Assertion `isa(Val) && “cast() argument of incompatible type!”’ failed.

0 opt 0x00000000010e3abf

1 opt 0x00000000010e5a22

2 libpthread.so.0 0x0000003dd0a0f710

3 libc.so.6 0x0000003dd0232925 gsignal + 53

4 libc.so.6 0x0000003dd0234105 abort + 373

5 libc.so.6 0x0000003dd022ba4e

6 libc.so.6 0x0000003dd022bb10 __assert_perror_fail + 0

7 opt 0x0000000000bf238f

8 opt 0x0000000001083af1 llvm::MPPassManager::runOnModule(llvm::Module&) + 497

9 opt 0x0000000001083c6b llvm::PassManagerImpl::run(llvm::Module&) + 171

10 opt 0x000000000053b307 main + 6999

11 libc.so.6 0x0000003dd021ed1d __libc_start_main + 253

12 opt 0x000000000052c5c9

Stack dump:

  1. Program arguments: opt -O2 -S gblmod2.ll -o gblmod2.opt.ll

  2. Running pass ‘Global Variable Optimizer’ on module ‘gblmod2.ll’.

Is it a BUG ?

Seb

Previously it was impossible to create an alias with an offset into a global. It appears you’ve found a way to workaround the check in the verifier, and that understandably crashes LLVM.

Rafael recently relaxed this restriction in trunk LLVM, so aliases can now be arbitrary constant expressions. It should support your example. It is now possible to represent some aliases in LLVM that cannot be compiled, so be careful.