Skip to content

Commit cd65ed2

Browse files
authored
Update 2025-11-30-comptime-c-functions.md
1 parent 46a2c0b commit cd65ed2

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

_posts/2025-11-30-comptime-c-functions.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,32 @@ int main() {
192192
193193
# Generic Hash Map
194194
195-
Although Clang manages to completely optimize the macro-based hash map away, GCC doesn't, even when passed these extra flags:
195+
Clang manages to completely optimize a macro-based hash map away.
196+
197+
GCC doesn't on the other hand, even when passed these extra flags:
196198
- `-finline-limit=999999`
197199
- `--param max-inline-insns-single=999999`
198200
- `--param max-inline-insns-auto=999999`
199201
202+
It still keeps the `calloc()` and `free()` around:
203+
```nasm
204+
"main":
205+
sub rsp, 8
206+
mov esi, 13
207+
mov edi, 2
208+
call "calloc"
209+
mov QWORD PTR [rax+5], OFFSET FLAT:.LC0
210+
mov rdi, rax
211+
call "free"
212+
mov edi, OFFSET FLAT:.LC1
213+
call "puts"
214+
xor eax, eax
215+
add rsp, 8
216+
ret
217+
```
218+
219+
But GCC manages to optimize them away when the `printf("All tests passed.\n");` at the end of `main()` is removed, for some reason?!
220+
200221
Copy of the code on [Compiler Explorer](https://godbolt.org/z/eecK3rK7z):
201222

202223
```c
@@ -313,6 +334,5 @@ static inline void macro_version(size_t capacity) {
313334
int main() {
314335
size_t capacity = 2;
315336
macro_version(capacity);
316-
printf("All tests passed.\n");
317337
}
318338
```

0 commit comments

Comments
 (0)