Preventing compiler optimizations while benchmarking

tl;dr doNotOptimizeAway creates an artificial “use”s. A little bit of terminology here: a “def” (“definition”) is a statement, which assigns a value to a variable; a “use” is a statement, which uses the value of a variable to perform some operation. If from the point immediately after a def, all the paths to the program … Read more

How is P0522R0 breaking code?

You can have code like this: template<template<typename> typename> struct Foo {}; template<typename, typename = void> struct Bar {}; Foo<Bar> unused; Without the defect resolution, unused would be ill-formed, because foo takes a template with only one template parameter, and not two. If you relied on this (maybe for SFINAE): template<template<typename> typename> void foo(); template<template<typename, typename> … Read more

GCC(/Clang): Merging functions with identical instructions (COMDAT folding)

Neither GCC nor Clang is a linker, and ICF needs to be done by the linker, or at least with cooperation with the linker. Edit: They don’t do ICF, so yes, distinct instantiations produce distinct code. The GNU gold linker supports ICF with the –icf option, which needs the GCC option -ffunction-sections to be used. … Read more

Is there some literal dictionary or array syntax in Objective-C?

With this change to the LLVM codebase, Apple has added a new syntax for literals in upcoming versions of the Clang compiler. Before, arrays were created using a C-based array and were converted on the fly into Objective-C objects, such as: NSArray* array = [NSArray arrayWithObjects: @”One”, @”Two”, @”Three”, nil]; Note that since this is … Read more

Switching between GCC and Clang/LLVM using CMake

CMake honors the environment variables CC and CXX upon detecting the C and C++ compiler to use: $ export CC=/usr/bin/clang $ export CXX=/usr/bin/clang++ $ cmake .. — The C compiler identification is Clang — The CXX compiler identification is Clang The compiler specific flags can be overridden by putting them into a make override file … Read more