Repository: mesonbuild/meson

Issue:
`--optimization=g` doesn't work with clang
**Describe the bug**
When specifying `--optimization=g` during meson setup the `-Og` `CFLAG` is applied only for builds using `gcc`, not in `clang` ones.

**To Reproduce**
`meson.build`
```meson
project('hello', 'c')
executable('hello', 'hello.c')
```

`hello.c`
```c
#include <stdio.h>

int main(void) {
	puts("Hello world");
	return 0;
}
```

Reproducer (with clang):
```
$ rm -fr build
$ CC=clang CXX=clang++ meson build --optimization=g
The Meson build system
Version: 0.53.1
Source dir: /root/test
Build dir: /root/test/build
Build type: native build
Project name: hello
Project version: undefined
C compiler for the host machine: clang (clang 10.0.0 "clang version 10.0.0 (Fedora 10.0.0-0.1.rc1.fc32)")
C linker for the host machine: clang GNU ld.bfd 2.33.1-12
Host machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 1

Found ninja-1.10.0 at /usr/bin/ninja
$ ninja -v -C build
ninja: Entering directory `build'
[1/2] clang -Ihello@exe -I. -I.. -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -MD -MQ 'hello@exe/hello.c.o' -MF 'hello@exe/hello.c.o.d' -o 'hello@exe/hello.c.o' -c ../hello.c
[2/2] clang  -o hello 'hello@exe/hello.c.o' -Wl,--as-needed -Wl,--no-undefined
```

Notice the missing `-Og` from the clang command line.

**Expected behavior**
Build using `gcc`:

```
$ rm -fr build
$ CC=gcc CXX=g++ meson build --optimization=g
The Meson build system
Version: 0.53.1
Source dir: /root/test
Build dir: /root/test/build
Build type: native build
Project name: hello
Project version: undefined
C compiler for the host machine: gcc (gcc 10.0.1 "gcc (GCC) 10.0.1 20200123 (Red Hat 10.0.1-0.5)")
C linker for the host machine: gcc GNU ld.bfd 2.33.1-12
Host machine cpu family: x86_64
Host machine cpu: x86_64
Build targets in project: 1

Found ninja-1.10.0 at /usr/bin/ninja
$ ninja -v -C build
ninja: Entering directory `build'
[1/2] gcc -Ihello@exe -I. -I.. -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Og -g -MD -MQ 'hello@exe/hello.c.o' -MF 'hello@exe/hello.c.o.d' -o 'hello@exe/hello.c.o' -c ../hello.c
[2/2] gcc  -o hello 'hello@exe/hello.c.o' -Wl,--as-needed -Wl,--no-undefined
```

The `-Og` flag is present.

**system parameters**
```
$ cat /etc/fedora-release 
Fedora release 32 (Rawhide)
$ rpm -q python3 meson ninja-build gcc clang
python3-3.8.1-2.fc32.x86_64
meson-0.53.1-1.fc32.noarch
ninja-build-1.10.0-1.fc32.x86_64
gcc-10.0.1-0.5.fc32.x86_64
clang-10.0.0-0.1.rc1.fc32.x86_64
```



Discussion:
Confirmed: with OS X clang and meson 0.53.1, `-Og` is NOT supplied when using `optimization=g`. 
I see the problem, preparing a PR.

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
@@ -19,7 +19,6 @@
 
 from ... import mesonlib
 from ...linkers import AppleDynamicLinker
-from ..compilers import clike_optimization_args
 from .gnu import GnuLikeCompiler
 
 if T.TYPE_CHECKING:
@@ -32,6 +31,14 @@
     'never': ['-Xclang', '-fno-color-diagnostics'],
 }  # type: T.Dict[str, T.List[str]]
 
+clang_optimization_args = {
+    '0': [],
+    'g': ['-Og'],
+    '1': ['-O1'],
+    '2': ['-O2'],
+    '3': ['-O3'],
+    's': ['-Os'],
+}  # type: T.Dict[str, T.List[str]]
 
 class ClangCompiler(GnuLikeCompiler):
     def __init__(self):
@@ -49,7 +56,7 @@ def get_colorout_args(self, colortype: str) -> T.List[str]:
         return clang_color_args[colortype][:]
 
     def get_optimization_args(self, optimization_level: str) -> T.List[str]:
-        return clike_optimization_args[optimization_level]
+        return clang_optimization_args[optimization_level]
 
     def get_pch_suffix(self) -> str:
         return 'pch'


Test patch: