question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Seems like `optimization=0` does nothing

See original GitHub issue

Describe the bug

It seems that optimization=0 does not have any effect. i.e. -O0 does not appear in the compiling command when using optimization=0.

To Reproduce

With the following code:

// meson.build
project('hello', 'c')
executable('hello', 'hello.c')

// hello.c
#include <stdio.h>
int main(void) {
	puts("Hello world");
	return 0;
}

And using the following commands:

meson setup buildir -Doptimization=0
cd buildir
meson compile -v

I obtain:

ninja: Entering directory `.'
[1/2] gcc -Ihello.p -I. -I.. -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -MD -MQ hello.p/hello.c.o -MF hello.p/hello.c.o.d -o hello.p/hello.c.o -c ../hello.c
[2/2] gcc  -o hello hello.p/hello.c.o -Wl,--as-needed -Wl,--no-undefined

Expected behavior

I expected to see -O0 to be passed as an option to GCC.

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?: native
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.): NixOS
  • what Python version are you using e.g. 3.8.0
  • what meson --version: 0.57.1
  • what ninja --version if it’s a Ninja build: 1.10.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eli-schwartzcommented, Jul 13, 2021

Yes, it is the clang default too, which is why the clang mixin returns an empty list too.

The base compiler class emits -O0, it’s only for the compilers which meson knows default to it, that don’t bother to emit this argument in the generated CLI.

0reactions
Pamplemoussecommented, Jul 13, 2021

This is only a clang issue, not a GCC one?

Dunno, I haven’t verified it on gcc, but their documentation explicitely say that -O0 is the baseline.

the truth of the matter is that clang doesn’t actually say straight out that -O0 is the default…

Yeah, I looked at the documentation for a little, and the default does not seem to correspond to any of the -O*.

Read more comments on GitHub >

github_iconTop Results From Across the Web

why optimization does not happen? - Stack Overflow
I have C/C++ code, that looks like this: static int function(double *I) { int n = ...
Read more >
[TF2.0]: Skipping optimization due to error while loading ...
However, this warning message constantly appears that shows "skipping optimization due to error while loading function libraries: Invalid ...
Read more >
Optimize Options (Using the GNU Compiler Collection (GCC))
Most optimizations are completely disabled at -O0 or if an -O level is not set on the command line, even if individual optimization...
Read more >
Does C++ compiler remove/optimize useless parentheses?
The answer here is no, the compiler does nothing different in its optimisation phase depending on ... It might seems like a very...
Read more >
Optimization: box volume (Part 1) (video) - Khan Academy
How to approach the optimization questions in calculus ? Each question seems to be very different in its approach . Can someone please...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found