RSSAmplifier

Blog

Shafik Yaghmour's Blog

Blog about C++, C, Undefined Behavior and Compilers

shafik.github.ioRSS feed ↗10 posts

Latest posts

Why Good Summaries are Important to a Pull Request

Why Good Summaries are Important to a Pull Request Code Reviewers are a precious resource in an open source project, often they have limited bandwidth. A critical goal when drafting a Pull Request (PR) should be, how does one minimize the amount of time it takes a reviewer to do a review. Especially we want to minimize context switches , which can have a large impact on productivity . Today I am…

What You Need to Know when Optimizations Changes the Behavior of Your C++ 😱

It is often said by those who have been around C++ for a long time that: “If the behavior of your program changes when using some level of optimization, then it is likely you have undefined behavior”. This is not to say that there are no compiler bugs they do happen but chances are what you are seeing is likely not a compiler bug. While this is all true, there is a catch here. If someone suspects…

Triaging clang C++ frontend bugs

Triaging clang C++ frontend bugs I have been triaging clang C++ frontend bugs for about a couple of years now and I wanted to share some of the lessons I have learnt in the hopes that others in the C++/LLVM community can feel less intimidated and get in on the fun as well. I have tried to develop some good practices for triaging and I have attempted to distill those here as well. The clang…

Auto Auto Auto

Auto Auto Auto In my C++ quiz #237 I asked the following question #237 Given the following in C++: struct A {}; using T = auto () -> auto ( * )() -> auto ( * )() -> A ; // Without checking, is this well-formed? The short answer is, Yes. The likely follow-up question is, what does T represent? Peeling the Onion Often when we have a complicated declaration, it is helpful to break it down into…

Let's enumerate the UB

Let’s enumerate the UB Some time ago I started working on P1705 Enumerating Core Undefined Behavior , I have collected a large set of undefined behavior ( UB ) during that time. There is going to be a lot of work involved in getting the annex into shape and editing it into the standard. While this work is ongoing, I will take some time to write blog posts to explore the set of undefined behaviors.…

Exploring Clangs Enum implementation and How we Catch Undefined Behavior

Intro In Part 1: Enums In C++, Choice is Oft Beguiled I talked about how enums work in C++ and the various choices we have. If you are not familiar with how enums work reading part 1 will help you to understand part 2. In this part we will dive into some of the clang internals for tracking the range of values of an enum and how it is used by UBSan and the optimizer. Finally we will look at…

Enums In C++, Choice is Oft Beguiled

The Basics In C++ we have several different options for enum types. These different choices affect the scope the enumerators are available in, the range of underlying values we can use and even whether setting certain values to an enum invokes undefined behavior . We are going to explore the different choices available and the consequences of those choices. I will follow this post with a second…

C++ initialization, arrays and lambdas oh my!

I recently ran a C++ weekly quiz #198 with the following code: int main () { int arr [ 5 ]{ 1 , 2 }; return arr [ [](){ return 4 ;}() ]; // What does main return? } Likely folks will be surprised that this does not compile ( see it live ). The standard says that two consecutive [ shall only be used to introduce an attribute, see [dcl.attr.grammar]p7 : Two consecutive left square bracket tokens…

The Usual Arithmetic Confusions

There are a lot of aspects of C++ that are not well understood and lead to all sorts of confusion. The usual arithmetic conversions and the integral promotions are two such aspects. Certain binary operators (arithmetic, relational and spaceship) require their operands to have a common type . The usual arithmetic conversions are the set of steps that gets operands to a common type . While the…

CppCon 2021 Trip Report

CppCon 2021 was a hybrid format this year due to Covid-19 still not being done with us. Folks were allowed on site with proof of vaccination but folks were also allowed to attend completely remote. Last year was fully online and that was a pretty positive experience for me . This year I still wasn’t sure what to expect since I was attending remotely because it was a hybrid format. The schedule was…