Repository: mesonbuild/meson

Issue:
Seems like `optimization=0` does nothing
**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:
```C
// 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:
```C
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](https://mesonbuild.com/Cross-compilation.html) 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**


Discussion:
`-O0` is the default, so meson's gcc mixin explicitly returns an empty list when asked for the flags for optimization=0.

Why is your expected behavior, the behavior you expect? When do you need this default to be hardcoded in the generated command line?
Is it the default in `clang` too?
(I am using `clang` on my project, and I though I saw discrepancies between when I manually used `-O0` or not, before starting to use `meson`...)

I need it to be hardcoded in the generated CLI not to rely on knowledge of the defaults of each compilers projects might use...
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.
Actually, I see differences between using `-O0`, and not providing anything (using the default).

For example, on the same source code, the following commands:
```bash
$ clang -o exe_default.out hello.c
$ clang -O0 -o exe_0.out hello.c
```

Respectively produce the following:
```asm
# objdump -D -M intel exe_default
[...]
0000000000401150 <main>:
  401150:	50                   	push   rax
  401151:	48 8d 3d ac 0e 00 00 	lea    rdi,[rip+0xeac]        # 402004 <_IO_stdin_used+0x4>
  401158:	e8 d3 fe ff ff       	call   401030 <puts@plt>
  40115d:	31 c0                	xor    eax,eax
  40115f:	59                   	pop    rcx
  401160:	c3                   	ret    
  401161:	66 2e 0f 1f 84 00 00 	nop    WORD PTR cs:[rax+rax*1+0x0]
  401168:	00 00 00 
  40116b:	0f 1f 44 00 00       	nop    DWORD PTR [rax+rax*1+0x0]
[...]

# objdump -D -M intel exe_0
[...]
0000000000401150 <main>:
  401150:	55                   	push   rbp
  401151:	48 89 e5             	mov    rbp,rsp
  401154:	48 83 ec 10          	sub    rsp,0x10
  401158:	c7 45 fc 00 00 00 00 	mov    DWORD PTR [rbp-0x4],0x0
  40115f:	48 8d 3d 9e 0e 00 00 	lea    rdi,[rip+0xe9e]        # 402004 <_IO_stdin_used+0x4>
  401166:	e8 c5 fe ff ff       	call   401030 <puts@plt>
  40116b:	31 c9                	xor    ecx,ecx
  40116d:	89 45 f8             	mov    DWORD PTR [rbp-0x8],eax
  401170:	89 c8                	mov    eax,ecx
  401172:	48 83 c4 10          	add    rsp,0x10
  401176:	5d                   	pop    rbp
  401177:	c3                   	ret    
  401178:	0f 1f 84 00 00 00 00 	nop    DWORD PTR [rax+rax*1+0x0]
  40117f:	00 
[...]
```

Resolving patch:
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -35,7 +35,7 @@
 }  # type: T.Dict[str, T.List[str]]
 
 clang_optimization_args = {
-    '0': [],
+    '0': ['-O0'],
     'g': ['-Og'],
     '1': ['-O1'],
     '2': ['-O2'],


Test patch: