Switch -g disables optimizations.
Joakim via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Thu Oct 8 22:46:44 PDT 2015
On Friday, 9 October 2015 at 04:22:51 UTC, Marco Leise wrote:
> I found the root for the horrible codegen with ldc2 I was
> experiencing. As soon as I added -g to get some line numbers in
> disassemblies, one or more optimizations steps got disabled.
>
> int main(string[])
> {
> return 0;
> }
>
> compiles with -O to:
>
> xor eax,eax
> ret
>
> and with -O -g to:
>
> push rbp
> mov rbp,rsp
> xor eax,eax
> pop rbp
> ret
>
> ldc2 -version:
> LDC - the LLVM D compiler (0.16.0):
> based on DMD v2.067.1 and LLVM 3.6.2
>
> Is that expected to improve the debugging experience and make
> local variables always available or a bug? clang's codegen is
> not influenced in this way by the -g flag.
Optimization is turned off in debug mode, with a comment claiming
debug info doesn't work with optimization:
https://github.com/ldc-developers/ldc/blob/9d3dd1f609e08f001aeec2cacb1c55707f37884b/gen/optimizer.cpp#L179
More information about the digitalmars-d-ldc
mailing list