FireBurn wrote:

Thanks, I've reworked it so the constant evaluator handles the builtin. The 
result is an lvalue based on the call, the same way `__builtin_function_start` 
is represented, so the evaluator only copies it around and CodeGen turns it 
into the `__ImageBase` subtraction. The `Expr::isConstantInitializer` special 
case and the `CGExprConstant` visitor are gone. Offsets added to the result are 
applied to the address before the subtraction

It also works outside a constant context now: `unsigned f() { return 
__builtin_imgrel32(f); }` is emitted as the same constant expression, through a 
shared helper in `CodeGenModule`. There the `__ImageBase` reference goes 
through `.refptr` on MinGW, so it is computed at run time rather than being a 
relocation. That seemed acceptable for a function body, but say if you would 
rather it were rejected there

On which declarations are accepted: global variables, elements of them and 
functions. I reject local variables, thread-local variables and `dllimport` 
declarations, since none of them has an offset from this image's base. There 
are Sema tests for each

I haven't taught the bytecode interpreter to evaluate it, it only has the 
opaque call entry like the other builtins of this kind. Let me know if you want 
that in this PR


https://github.com/llvm/llvm-project/pull/237119
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to