62 questions
3 votes
2 answers
120 views
/kernel mode in MSVC cl.exe allows new despite specifying user must explicitly define the operator
According to documentation, under /kernel mode: You must explicitly define the new() or delete() operator. The compiler and runtime don't supply a default definition. Yet, the following code ...
1 vote
1 answer
103 views
Minimal example in Compiler Explorer (GodBolt.org) using the Abseil library
I'm trying to set up such a minimal project using the library, but no matter what I try I can't import it: #include <iostream> #include "absl/time/clock.h" int main() { std::cout ...
-2 votes
4 answers
207 views
How can I see the assembly generated for my code?
I have a case where I have a bitfield that I know starts off as all zeros. And then I then I have something like: if (isTrue) bitfield |= flag; And what I wanted to do was to set it without ...
4 votes
0 answers
412 views
Why does a simple C++ const array loop break GCC 11.2 assembly output on Compiler Explorer, but not GCC 15 or MSVC/ICX?
I've been investigating the assembly output for a simple C++ loop involving a const array and const size, and I've encountered peculiar version-specific behavior with GCC on Compiler Explorer. My ...
2 votes
1 answer
182 views
Show compiler's estimate of branch/block probabilities
How can I get clang or compiler explorer to emit information about its internal calculated branch probabilities for a snippet of C++ code? It's OK if it's in IR at some optimization pass and not in ...
0 votes
1 answer
125 views
How can this Nim function deal with the special case at compile time?
I'm not a Nim user, but I was astonished by how the solution for this exercise on Exercism. The text of the exercise is as follows: Your task is to convert a number into its corresponding raindrop ...
2 votes
1 answer
85 views
Show "rodata" section in Compiler Explorer IDE mode
When I compile a single file in Compiler Explorer I can see all the constants like string literals in the output window. const char* ss = "abcdef"; E.g. here https://godbolt.org/z/hEzTG7d7c ...
1 vote
0 answers
81 views
How to implement a Swift analogue of `benchmark::DoNotOptimize`?
I would like to do some (micro)benchmarking in Swift. I have been using package-benchmark for this. It comes with a blackHole helper function that forces the compiler to assume that a variable is read ...
3 votes
1 answer
236 views
Understanding the x86_64 call instruction on a 64bit system
I'm exploring some disassembled C programs with godbolt and I am having trouble wrapping my head around the x86_64 "call" instruction. With the C code: int func(int i) { return i + 1; } ...
0 votes
1 answer
101 views
Undefined behaviour? Local vs global scope and pointer to temporary array
I have this source code: #include <iostream> #include <cstdint> #include <cstring> struct bt_data { uint8_t type; uint8_t data_len; const uint8_t* data; }; static const char* ...
2 votes
0 answers
108 views
"single" command line argument which contains spaces is getting treated as multiple arguments
In godbolt compiler explorer (https://godbolt.org/z/Gqc5PeKz8) I am passing a single argument which contains spaces inside quotes, but it looks they are getting treated as separate arguments: #include ...
2 votes
1 answer
105 views
Where is the binary code for executing `std::vector<T>::operator[]`, when a TU calling that function is compiled with -O0?
If I compile the following with -O3 #include <vector> int foo() { std::vector<int> const v{17,2,3}; return v[0] + v[2]; } the assembly I get is foo(): mov eax, 20 ...
5 votes
0 answers
3k views
How can I see the console output in Compiler Explorer (Godbolt)? [closed]
If I compile a piece of code that writes to the console I can't see anything, only the assembly code on the right. Link. How I can I see what's printed from a call to std::cout?
3 votes
1 answer
240 views
Setting AVX512 vector to zero/non-zero sometimes causes signal SIGILL on Godbolt
On Godbolt, this executes fine: volatile __m512i v = _mm512_set_epi64(1, 0, 0, 0, 0, 0, 0, 0); but all zeros does not: volatile __m512i v = _mm512_set_epi64(0, 0, 0, 0, 0, 0, 0, 0); It ...
0 votes
1 answer
90 views
Confusion about the linker error regarding static class members
I faced the unresolved symbol linker error regarding a static member of a class. I have found this and some other threads which learned me, that I have to declare an instance of the static member ...