# undefined\_behavior

Undefined behavior is behavior for which a programming-language standard imposes no requirements, potentially producing unpredictable results or terminating execution.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## How can undefined opcodes ud0 and ud1 have parameters? How undefined were they?

DevFeed: [How can undefined opcodes ud0 and ud1 have parameters? How undefined were they?](<https://devfeed.tech/articles/how-can-undefined-opcodes-ud0-and-ud1-have-parameters-how-undefined-were-they-67004.md>)

Original publisher: [Read original article](<https://devblogs.microsoft.com/oldnewthing/20261007-00/?p=112759/>)

Author: Raymond Chen

Published: 2026-10-07T14:00:00Z

Content type: article

Language: en

Sources: [Raymond Chen](<https://devfeed.tech/sources/raymond-chen.md>)

Topics: [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [image retention policy](<https://devfeed.tech/topics/image-retention-policy.md>)

Tags: [6502](<https://devfeed.tech/tags/6502.md>), [history](<https://devfeed.tech/tags/history.md>), [intel](<https://devfeed.tech/tags/intel.md>), [invalid-opcode](<https://devfeed.tech/tags/invalid-opcode.md>), [old-new-thing](<https://devfeed.tech/tags/old-new-thing.md>), [sse](<https://devfeed.tech/tags/sse.md>), [undocumented](<https://devfeed.tech/tags/undocumented.md>)

### AI overview

The post explains how the x86 opcodes ud0 and ud1 could be undefined yet still have operands: the processor decoded operand fields before raising an invalid opcode exception. It describes how software reliance on the unofficial behavior of 0F FF led Intel to place PADDQ at 0F D4 to preserve compatibility. It also gives examples of parameterized undefined instructions on other architectures.

### Source excerpt

They weren't defined, not even as undefined. The post How can undefined opcodes <CODE>ud0</CODE> and <CODE>ud1</CODE> have parameters? How undefined were they? appeared first on The Old New Thing.

## Why is the x86 undefined instruction called ud2?

DevFeed: [Why is the x86 undefined instruction called ud2?](<https://devfeed.tech/articles/why-is-the-x86-undefined-instruction-called-ud2-61204.md>)

Original publisher: [Read original article](<https://blog.adafruit.com/2026/09/28/why-is-the-x86-undefined-instruction-called-ud2/>)

Author: Anne Barela

Published: 2026-09-28T20:32:34Z

Content type: article

Language: en

Sources: [Adafruit Industries](<https://devfeed.tech/sources/adafruit-industries-makers-hackers-artists-designers-and-engineers.md>)

Topics: [x86](<https://devfeed.tech/topics/x86.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Compilers and Linkers](<https://devfeed.tech/topics/compilers-and-linkers.md>)

Tags: [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [exception](<https://devfeed.tech/tags/exception.md>), [invalid-opcode](<https://devfeed.tech/tags/invalid-opcode.md>), [old-new-thing](<https://devfeed.tech/tags/old-new-thing.md>), [software](<https://devfeed.tech/tags/software.md>), [vintage-computing](<https://devfeed.tech/tags/vintage-computing.md>), [x86](<https://devfeed.tech/tags/x86.md>)

### AI overview

Raymond Chen explains the history and behavior of the x86 ud2 instruction. Compilers use it to mark unreachable code and ensure that an unexpected return from a [[noreturn]] function causes an invalid opcode exception. Earlier faulting byte sequences were less reliable because some encoded unused operands could cause an access violation when decoding crossed into an unmapped page.

### Source excerpt

Raymond Chen, writing at The Old New Thing, explains the history behind the x86 instruction ud2. It is an architecturally undefined instruction that always raises an invalid opcode exception. Compilers emit it to mark unreachable code. If a function marked [[noreturn]] somehow returns, the compiler puts a ud2 after the call so the program crashes [...]

## \[$\] Reducing undefined behavior in the C language

DevFeed: [\[$\] Reducing undefined behavior in the C language](<https://devfeed.tech/articles/reducing-undefined-behavior-in-the-c-language-61380.md>)

Original publisher: [Read original article](<https://lwn.net/Articles/1095811/>)

Author: corbet

Published: 2026-09-28T15:16:22Z

Content type: article

Language: en

Sources: [LWN.net](<https://devfeed.tech/sources/lwn-net.md>)

Topics: [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>)

Tags: [2015](<https://devfeed.tech/tags/2015.md>), [2026](<https://devfeed.tech/tags/2026.md>), [abi](<https://devfeed.tech/tags/abi.md>), [abstract](<https://devfeed.tech/tags/abstract.md>), [annotations](<https://devfeed.tech/tags/annotations.md>), [architectures](<https://devfeed.tech/tags/architectures.md>), [array](<https://devfeed.tech/tags/array.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [buffer](<https://devfeed.tech/tags/buffer.md>), [buffer-overflow](<https://devfeed.tech/tags/buffer-overflow.md>), [bug](<https://devfeed.tech/tags/bug.md>), [bugs](<https://devfeed.tech/tags/bugs.md>), [c](<https://devfeed.tech/tags/c.md>), [c-language](<https://devfeed.tech/tags/c-language.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [language](<https://devfeed.tech/tags/language.md>), [linux](<https://devfeed.tech/tags/linux.md>), [memory](<https://devfeed.tech/tags/memory.md>), [talk](<https://devfeed.tech/tags/talk.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

C's undefined behavior gives implementations room for hardware support and optimization, but can leave programs without expected semantics and enable surprising compiler transformations. The article gives examples involving division by zero, observable side effects, and volatile stores, and notes that C23 added a "no time travel" rule for one such case. Mitigations include compiler warnings, static analysis, sanitizers, and formal verification; C2y's draft has removed 45 of roughly 100 instances of undefined behavior. Type and bounds safety can be improved with annotations, diagnostics, and checks, while temporal safety remains harder: Rust has an advantage, and CHERI and Fil-C can help. Full memory safety would require costly runtime checks or formal verification; the author expects the strongest near-term results from restricted C combined with formal methods.

### Source excerpt

As a professor of biomedical engineering, Martin Uecker perhaps does not fit the profile of a typical presenter at Kernel Recipes. He is, however, a longtime Linux user, and works on free software for controlling magnetic resonance imaging (MRI) scanners. He was at the conference to talk about the C programming language, the specific problem of undefined behavior in C, and whether it can eventually be made into a memory-safe language.

## std::call\_once vs. std::async

DevFeed: [std::call\_once vs. std::async](<https://devfeed.tech/articles/std-call-once-vs-std-async-42168.md>)

Original publisher: [Read original article](<https://devblogs.microsoft.com/oldnewthing/20260917-00/?p=112706>)

Author: Raymond Chen

Published: 2026-09-17T14:00:00Z

Content type: article

Language: en

Sources: [Raymond Chen](<https://devfeed.tech/sources/raymond-chen.md>)

Topics: [async](<https://devfeed.tech/topics/async.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [execution](<https://devfeed.tech/topics/execution.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [async](<https://devfeed.tech/tags/async.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [exception](<https://devfeed.tech/tags/exception.md>), [execution](<https://devfeed.tech/tags/execution.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [old-new-thing](<https://devfeed.tech/tags/old-new-thing.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

This article compares std::call_once with std::async for deferred execution in C++. It discusses retrieving cached results, repeated calls, thread safety, memory allocation, supported execution modes, and exception behavior, with additional commentary on implementation defects and data races in an older GCC implementation.

### Source excerpt

Simple vs complex machinery. The post <CODE>std::call_once</CODE> vs. <CODE>std::async</CODE> appeared first on The Old New Thing.

## C++26: Trivial infinite loops are no longer undefined behaviour

DevFeed: [C++26: Trivial infinite loops are no longer undefined behaviour](<https://devfeed.tech/articles/c-26-trivial-infinite-loops-are-no-longer-undefined-behaviour-53295.md>)

Original publisher: [Read original article](<https://www.sandordargo.com/blog/2026/09/16/cpp26-trivial-infinite-loops>)

Author: Sandor Dargo

Published: 2026-09-15T22:00:00Z

Content type: article

Language: en

Sources: [Sandor Dargo's Blog](<https://devfeed.tech/sources/sandor-dargo-s-blog.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>)

Tags: [atomic](<https://devfeed.tech/tags/atomic.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dev](<https://devfeed.tech/tags/dev.md>), [optimize](<https://devfeed.tech/tags/optimize.md>), [support](<https://devfeed.tech/tags/support.md>), [undefined-behaviour](<https://devfeed.tech/tags/undefined-behaviour.md>)

### AI overview

This article explains why side-effect-free infinite loops were undefined behavior in C++ before C++26, how compilers could optimize them away, and how proposal P2809R3 makes trivial infinite loops well-defined. It also discusses the differing C rules and the use of such loops as halt-on-error patterns in embedded and kernel code.

### Source excerpt

Let's start with a question! Is this program well-defined? int main() { while (true) ; } If you said yes, you'd be wrong -- at least before C++26. A while (true); loop with no side effects used to be undefined behaviour. Compilers were free to assume it terminates, and some -- Clang in particular -- would optimize it away entirely, with spectacular consequences: // https://godbolt....

## C++26: Standard Library Hardening Experiments

DevFeed: [C++26: Standard Library Hardening Experiments](<https://devfeed.tech/articles/c-26-standard-library-hardening-experiments-53318.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2026/hardening-experiments/>)

Published: 2026-08-30T00:00:00Z

Content type: article

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [standard](<https://devfeed.tech/topics/standard.md>), [Error Handling](<https://devfeed.tech/topics/error-handling.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [implementation](<https://devfeed.tech/topics/implementation.md>), [interface](<https://devfeed.tech/topics/interface.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [contracts](<https://devfeed.tech/tags/contracts.md>), [error-handling](<https://devfeed.tech/tags/error-handling.md>), [exception](<https://devfeed.tech/tags/exception.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [standard](<https://devfeed.tech/tags/standard.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>), [undefined-behaviour](<https://devfeed.tech/tags/undefined-behaviour.md>)

### AI overview

An explanation of C++26 standard-library hardening, using vector element access to show how hardened implementations turn certain invalid accesses into contract violations with terminating behavior instead of undefined behavior. It distinguishes hardening from bounds-checked access through at() and discusses the relationship to Contracts and exception handling.

### Source excerpt

"Hardening" seems to be a very popular term in the C++ World in 2026. In this article we'll explore what this word means and see some core examples. Can a hardened library make C++ fully safe? Let's find out. The Core Idea When you learned about std::vector you may remember that you can access an element at the i-th position using at least two expressions: std::vector<int> v { 1, 2, 3, 4 }; v[i] = 10; // for some i v.at(j) = 11; // for some j The main difference between those two is that [] is unchecked (and can generate undefined behaviour if you try to access an element which is not there), while .at() may throw std::out_of_range (so it's a well defined behaviour). C++26 Changes In C++26, the Standard introduces the notion of a hardened implementation. Whether a standard-library implementation is hardened, and how that mode is enabled, is implementation-defined. For std::vector<T, Allocator>::operator[](size_type pos): C++ Standard Condition until C++26 If pos < size() is false, the behavior is undefined. since C++26 If pos < size() is false: If the implementation is hardened, a contract violation occurs, If the implementation is not hardened, the behavior is undefined. In other words, if you switch this "hardened" mode you'll get some well specified error/violation rather than just an undefined behaviour. Let's untangle the wording and common questions: For .at() you may get an exception... so why do we need a new alternative? That's fair question. In short at() and [] has different interfaces and performance/error-handling approaches. What's more important you cannot turn exceptions off easily (you can, and std::terminate will be called, but that's not very flexible). So Hardening does not change operator[] into at() - it detects a programming error and terminates instead of allowing memory-unsafe undefined behaviour. "A contract violation occurs" - this is the key thing here. The "hardening" feature is expressed in terms of Contracts that also were accepted into

## This Month in Julia World (February 2026)

DevFeed: [This Month in Julia World (February 2026)](<https://devfeed.tech/articles/this-month-in-julia-world-february-2026-46365.md>)

Original publisher: [Read original article](<https://julialang.org/blog/2026/03/this-month-in-julia-world/index.html>)

Author: Stefan Krastanov

Published: 2026-03-01T00:00:00Z

Content type: article

Language: en

Sources: [JuliaLang - The Julia programming language](<https://devfeed.tech/sources/julialang-the-julia-programming-language.md>)

Topics: [The Julia Language](<https://devfeed.tech/topics/julia.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Code generation](<https://devfeed.tech/topics/code-generation.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Graphs](<https://devfeed.tech/topics/graphs.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>), [scheme](<https://devfeed.tech/topics/scheme.md>)

Tags: [2026](<https://devfeed.tech/tags/2026.md>), [c](<https://devfeed.tech/tags/c.md>), [code-generation](<https://devfeed.tech/tags/code-generation.md>), [community](<https://devfeed.tech/tags/community.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [graphs](<https://devfeed.tech/tags/graphs.md>), [newsletter](<https://devfeed.tech/tags/newsletter.md>), [undefined-behaviour](<https://devfeed.tech/tags/undefined-behaviour.md>)

### AI overview

A February 2026 community newsletter covering Julia development, including mutually recursive types, improved undefined-behavior documentation, compiler type analysis, moving default constructor generation into Julia, and work on background package precompilation.

### Source excerpt

Community Newsletter for February 2026

## San Diego C++ Meetup: Meeting #79 - October 2025 Edition - Hosting Hubert Liberacki!

DevFeed: [San Diego C++ Meetup: Meeting #79 - October 2025 Edition - Hosting Hubert Liberacki!](<https://devfeed.tech/articles/san-diego-c-meetup-meeting-79-october-2025-edition-hosting-hubert-liberacki-51139.md>)

Original publisher: [Read original article](<https://vorbrodt.blog/2025/10/23/san-diego-c-meetup-meeting-79-october-2025-edition-hosting-hubert-liberacki/>)

Author: Kobi

Published: 2025-10-24T01:59:38Z

Content type: article

Language: en

Sources: [Vorbrodt's C++ Blog](<https://devfeed.tech/sources/vorbrodt-s-c-blog.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Refactoring](<https://devfeed.tech/topics/refactoring.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Robotics](<https://devfeed.tech/topics/robotics.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [kobi](<https://devfeed.tech/tags/kobi.md>), [legacy-code](<https://devfeed.tech/tags/legacy-code.md>), [meetup](<https://devfeed.tech/tags/meetup.md>), [refactoring](<https://devfeed.tech/tags/refactoring.md>), [san-diego-c-plus-plus-meetup](<https://devfeed.tech/tags/san-diego-c-plus-plus-meetup.md>), [testing](<https://devfeed.tech/tags/testing.md>)

### AI overview

A recap of the 79th San Diego C++ Meetup, featuring Hubert Liberacki's presentation on safely testing private members in C++. The discussion covers challenges in legacy code, third-party libraries, debugging, instrumentation, and refactoring with test-driven development, along with the risks of macro hacks, undefined behavior, ABI mismatches, and portability failures.

### Source excerpt

Hello all! This time, our 79th meeting Oct 22 2025, we were hosting Hubert Liberacki who gave a fantastic presentation on "Cracking Open the Black Box: Legally Testing the Privates in C++". A huge thank you to everyone who attended and participated in the discussion! For those who couldn't make it or would like to [...]

## GSoC 2025: Usability Improvements for the Undefined Behavior Sanitizer

DevFeed: [GSoC 2025: Usability Improvements for the Undefined Behavior Sanitizer](<https://devfeed.tech/articles/gsoc-2025-usability-improvements-for-the-undefined-behavior-sanitizer-43122.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2025-09-01-gsoc-ubsan-trap-messages/>)

Author: Anthony Tran

Published: 2025-10-20T00:00:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [C](<https://devfeed.tech/topics/c.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [clang](<https://devfeed.tech/topics/clang.md>), [Objective-C](<https://devfeed.tech/topics/objective-c.md>), [Kernel](<https://devfeed.tech/topics/kernel.md>)

Tags: [2025](<https://devfeed.tech/tags/2025.md>), [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [codegen](<https://devfeed.tech/tags/codegen.md>), [debug](<https://devfeed.tech/tags/debug.md>), [gsoc](<https://devfeed.tech/tags/gsoc.md>), [improvements](<https://devfeed.tech/tags/improvements.md>), [kernel](<https://devfeed.tech/tags/kernel.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [sanitizer](<https://devfeed.tech/tags/sanitizer.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

This article reports on Google Summer of Code 2025 work to improve the usability of trapping Undefined Behavior Sanitizer (UBSan). It explains how trapping mode supports kernel, embedded, and production-hardening use cases, but previously made debugging undefined behavior difficult. The work improves the information available to developers when debugger execution stops on a sanitizer trap.

### Source excerpt

Introduction My name is Anthony and I had the pleasure of working on improving the Undefined Behavior Sanitizer this Google Summer of Code 2025. My mentors were Dan Liew and Michael Buch. Background Undefined Behavior Sanitizer (UBSan) is a tool for detecting a subset of the undefined behaviors in the C, C++, and Objective-C languages at runtime. This project focused mainly on the trapping variant of UBSan, which is evoked through -fsanitize-trap=<...> along with -fsanitize=<...>. Trapping UBSan is a lighter-weight version of UBSan because upon detection of undefined behavior a trap instruction is executed rather than calling into a runtime library to handle the undefined behavior. This makes it more appealing for kernel, embedded, and production hardening use cases. For cases of undefined behavior that can be detected by UBSan, check out the official clang documentation. An issue with trapping UBSan prior to my work was that it was much harder to debug undefined behavior when it is detected when compared to the non-trapping mode. To illustrate this consider this C program that reads integers from the command line arguments and adds them. #include <stdlib.h>#include <stdio.h>int add(int a, int b) { return a + b;}int main(int argc, const char** argv) { if (argc < 3) return 1; int a = atoi(argv[1]); int b = atoi(argv[2]); int result = add(a, b); printf("Added %d + %d = %d\n", a, b, result); return 0;} If this program is compiled and executed using UBSan with its userspace runtime it provides helpful output diagnosing the problem and also allows execution to continue. $ bin/clang -fsanitize=undefined add.c -g -o add && ./add 2147483647 1add.c:5:13: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior add.c:5:13 Added 2147483647 + 1 = -2147483648 In contrast when using UBSan in trapping mode the program immediately terminates when undefined behavior is detected as shown below. $

## Improving Code Safety in C++26: Managers and Dangling References

DevFeed: [Improving Code Safety in C++26: Managers and Dangling References](<https://devfeed.tech/articles/improving-code-safety-in-c-26-managers-and-dangling-references-53311.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2025/cpp26-safety-temp/>)

Published: 2025-01-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [bug](<https://devfeed.tech/topics/bug.md>), [toolchain](<https://devfeed.tech/topics/toolchain.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [diagnostics](<https://devfeed.tech/tags/diagnostics.md>), [error](<https://devfeed.tech/tags/error.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [static](<https://devfeed.tech/tags/static.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

A tutorial on improving a C++ configuration manager by fixing a dangling reference to a temporary object, using C++26 diagnostics to catch the error, and avoiding stack-overflow risks from large default configuration objects.

### Source excerpt

In this blog post, we'll explore ways to improve the safety of a simple configuration manager. We'll handle common pitfalls like dangling references and excessive stack usage. Additionally, we'll see how C++26 helps enforce safer coding practices with stricter diagnostics and improved handling of large objects. Let's go. Step 1: The Buggy Implementation Below is a simple example of a manager object that stores various configs in a map and provides a method to retrieve them. When a requested configuration isn't found, the code attempts to return a default certificate: #include <map> #include <string> #include <iostream> #include <vector> #include <cstdint> class ConfigManager { private: std::map<std::string, std::vector<uint8_t>> configs; public: ConfigManager() { configs["database"] = { 'h','o','s','t','=','l','o','c','a','l','h','o','s','t',';', 'p','o','r','t','=','5','4','3','2' }; } const std::vector<uint8_t>& findConfig(const std::string& name) const { auto it = configs.find(name); if (it != configs.end()) return it->second; return {42}; } }; int main() { ConfigManager configManager; const std::vector<uint8_t>& dbConfig = configManager.findConfig("database"); std::cout << "Database config: "; for (uint8_t byte : dbConfig) { std::cout << static_cast<char>(byte); } } See @Compiler Explorer Do you see a potential error in this code? . . . At first glance, the code looks harmless. However, if the requested entry isn't found, the function returns a reference to a temporary std::vector. Once the function exits, that temporary is destroyed--leaving you with a dangling reference and undefined behavior. Compiler Warnings Ok, the bug was easy... and compilers have warned about this case for a long time. While this is helpful, it's still possible to overlook or disable the warning, especially if your project is large. So let's try enabling C++26 mode... for example on GCC 14 you'll get: error: returning reference to temporary [-Wreturn-local-addr] Great! Now, we cannot skip th

## Fearless Concurrency Ep.4: Understanding Mutexes and Thread Safety in Rust

DevFeed: [Fearless Concurrency Ep.4: Understanding Mutexes and Thread Safety in Rust](<https://devfeed.tech/articles/fearless-concurrency-ep-4-understanding-mutexes-and-thread-safety-in-rust-22261.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/10/fearless-concurrency-ep4-understanding-mutexes-and-thread-safety-in-rust.html>)

Published: 2024-10-25T00:00:00Z

Content type: article

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Rust](<https://devfeed.tech/topics/rust.md>), [thread safe data sharing](<https://devfeed.tech/topics/thread-safe-data-sharing.md>), [locking](<https://devfeed.tech/topics/locking.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [synchronization](<https://devfeed.tech/topics/synchronization.md>), [race-condition](<https://devfeed.tech/topics/race-condition.md>), [Distributed Systems & Parallel Computing](<https://devfeed.tech/topics/distributed-systems-parallel-computing.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>)

Tags: [avoiding-race-conditions-in-rust](<https://devfeed.tech/tags/avoiding-race-conditions-in-rust.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrency-and-memory-management-in-rust](<https://devfeed.tech/tags/concurrency-and-memory-management-in-rust.md>), [concurrency-in-rust](<https://devfeed.tech/tags/concurrency-in-rust.md>), [managing-shared-data-in-rust](<https://devfeed.tech/tags/managing-shared-data-in-rust.md>), [mutex](<https://devfeed.tech/tags/mutex.md>), [mutex-and-drop-trait-in-rust](<https://devfeed.tech/tags/mutex-and-drop-trait-in-rust.md>), [mutexes-in-rust](<https://devfeed.tech/tags/mutexes-in-rust.md>), [race-conditions](<https://devfeed.tech/tags/race-conditions.md>), [rust](<https://devfeed.tech/tags/rust.md>), [rust-concurrency-best-practices](<https://devfeed.tech/tags/rust-concurrency-best-practices.md>), [rust-concurrency-guide](<https://devfeed.tech/tags/rust-concurrency-guide.md>), [rust-drop-trait-in-concurrency](<https://devfeed.tech/tags/rust-drop-trait-in-concurrency.md>), [rust-multithreading-tutorial](<https://devfeed.tech/tags/rust-multithreading-tutorial.md>), [rust-mutex-example](<https://devfeed.tech/tags/rust-mutex-example.md>), [rust-mutex-vs-lock](<https://devfeed.tech/tags/rust-mutex-vs-lock.md>), [rust-ownership-and-borrowing-in-concurrency](<https://devfeed.tech/tags/rust-ownership-and-borrowing-in-concurrency.md>), [rust-thread-safety](<https://devfeed.tech/tags/rust-thread-safety.md>), [rust-thread-safety-without-garbage-collection](<https://devfeed.tech/tags/rust-thread-safety-without-garbage-collection.md>), [safety](<https://devfeed.tech/tags/safety.md>), [thread-safety](<https://devfeed.tech/tags/thread-safety.md>), [thread-synchronization-in-rust](<https://devfeed.tech/tags/thread-synchronization-in-rust.md>), [understanding-poisoned-mutexes-in-rust](<https://devfeed.tech/tags/understanding-poisoned-mutexes-in-rust.md>)

### AI overview

The excerpt explains how Rust's ownership and borrowing rules govern variables shared across threads, including exclusive access and ensuring values outlive the threads that use them. It describes mutexes as enforcing mutual exclusion and says Rust's scope-based resource cleanup releases locks automatically. It also notes that the episode covers poisoned mutexes, which can result when a thread panics while holding a lock. The excerpt does not identify the specific Rust types or features by name.

### Source excerpt

Introduction: Welcome to Episode 4 of Fearless Concurrency in Rust! In this episode, we explore how Rust's ownership and borrowing rules impact multithreaded programming, focusing on the complexities of managing memory in a concurrent environment. We'll break down how Rust's strict borrowing and ownership model ensures safety and prevents common pitfalls like data races and undefined behavior, making it an ideal choice for building reliable multithreaded applications. Thread Safety and Ownership: Managing variables across threads using Rust's ownership rules.

## std::initializer\_list in C++ 2/2 - Caveats and Improvements

DevFeed: [std::initializer\_list in C++ 2/2 - Caveats and Improvements](<https://devfeed.tech/articles/std-initializer-list-in-c-2-2-caveats-and-improvements-53300.md>)

Original publisher: [Read original article](<https://www.cppstories.com/2023/initializer_list_improvements/>)

Published: 2024-09-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [C++ Stories](<https://devfeed.tech/sources/c-stories.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [class](<https://devfeed.tech/tags/class.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [container](<https://devfeed.tech/tags/container.md>), [copy](<https://devfeed.tech/tags/copy.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

This C++ tutorial examines caveats of std::initializer_list, including lifetime issues when returning lists, the cost of copying elements into containers, and failures with non-copyable types. It also discusses safer ways to address these limitations.

### Source excerpt

In this article, you'll learn why std::initializer_list has a bad reputation in C++. Is passing values using it as efficient as "emplace"? How can we use non-copyable types? You'll also see how to fix some of the problems. Let's start with the issues first: Updated in Sept 2024: Added note about stack overflow and C++26 fixes. This is the second part of initalizer_list mini-series. See the first part on Basics and use cases here. 1. Referencing local array If you recall from the previous article, std::initializer_list expands to some unnamed local array of const objects. So the following code might be super unsafe: std::initializer_list<int> wrong() { // for illustration only! return { 1, 2, 3, 4}; } int main() { std::initializer_list<int> x = wrong(); } The above code is equivalent to the following: std::initializer_list<int> wrong() { const int arr[] { 1, 2, 3, 4} return std::initializer_list<int>{arr, arr+4}; } int main() { std::initializer_list<int> x = wrong(); } The example serves to highlight the error, emphasizing the importance of avoiding similar mistakes in our own code. The function returns pointers/iterators to a local object, and that will cause undefined behavior. See a demo @Compiler Explorer. GCC or Clang reports a handy warning in this case: GCC: warning: returning temporary 'initializer_list' does not extend the lifetime of the underlying array [-Winit-list-lifetime] 5 | return { 1, 2, 3, 4}; Or in Clang: <source>:5:12: warning: returning address of local temporary object [-Wreturn-stack-address] return { 1, 2, 3, 4}; We can make the following conclusion: std::initializer_list is a "view" type; it references some implementation-dependent and a local array of const values. Use it mainly for passing into functions when you need a variable number of arguments of the same type. If you try to return such lists and pass them around, then you risk lifetime issues. Use with care. Let's take on another limitation: 2. The cost of copying elements Passing el

## Looking for Missed Alarm Bugs in a Formal Verification Tool

DevFeed: [Looking for Missed Alarm Bugs in a Formal Verification Tool](<https://devfeed.tech/articles/looking-for-missed-alarm-bugs-in-a-formal-verification-tool-39746.md>)

Original publisher: [Read original article](<https://blog.regehr.org/archives/2124>)

Author: regehr

Published: 2024-09-04T18:29:03Z

Content type: article

Language: en

Sources: [Embedded in Academia](<https://devfeed.tech/sources/embedded-in-academia.md>)

Topics: [Formal verification](<https://devfeed.tech/topics/formal-verification.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [C](<https://devfeed.tech/topics/c.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>)

Tags: [bugs](<https://devfeed.tech/tags/bugs.md>), [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [formal-verification](<https://devfeed.tech/tags/formal-verification.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [testing](<https://devfeed.tech/tags/testing.md>), [uncategorized](<https://devfeed.tech/tags/uncategorized.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>), [verification](<https://devfeed.tech/tags/verification.md>)

### AI overview

This co-authored article explains how formal verification tools themselves require rigorous engineering and testing. It describes testing Alive2, a translation validation tool for LLVM optimizations, including the challenge of finding missed-alarm bugs and the use of randomized program generation with YARPGen.

### Source excerpt

[This piece is co-authored with Vsevolod Livinskii.] Formal verification isn't some sort of magic pixie dust that we sprinkle over a computer system to make it better. Real formal verification involves a lot of the same kind of difficult, nasty, grungy engineering work that any other systems-level job involves. Furthermore, the verification tools themselves are [...]

## Blog: Falco Weekly 47 - 2023

DevFeed: [Blog: Falco Weekly 47 - 2023](<https://devfeed.tech/articles/blog-falco-weekly-47-2023-32510.md>)

Original publisher: [Read original article](<https://falco.org/blog/falco-w-47-2023-weekly-recap/>)

Published: 2023-11-24T00:00:00Z

Content type: article

Language: en

Sources: [Falco](<https://devfeed.tech/sources/falco-falco.md>)

Topics: [Falco](<https://devfeed.tech/topics/falco.md>), [Continuous integration](<https://devfeed.tech/topics/continuous-integration.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [async](<https://devfeed.tech/topics/async.md>)

Tags: [blog](<https://devfeed.tech/tags/blog.md>), [changes](<https://devfeed.tech/tags/changes.md>), [ci](<https://devfeed.tech/tags/ci.md>), [falco](<https://devfeed.tech/tags/falco.md>), [improvements](<https://devfeed.tech/tags/improvements.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>), [weekly](<https://devfeed.tech/tags/weekly.md>)

### AI overview

A weekly Falco community recap covering cleanup and fixes across Falco libraries, including async event queue and statistics updates, planned tracer deprecation and architecture support, a new official adopter, Falcoctl driver-command work, and the Driverkit v0.16.0 release.

### Source excerpt

Another week, another load of improvements everywhere in the falcosecurity! What happened in Falco this week? Let's go through the major changes that happened in various repositories under the falcosecurity organization. Libs The anticipated 0.14.0 libs tag (and its driver counterpart) are a bit late, unfortunately. Anyway, spring cleaning went on this week! removed stopwatch implementation, now unused: https://github.com/falcosecurity/libs/pull/1493 removed unused sinsp_test.cpp file: https://github.com/falcosecurity/libs/pull/1499 removed jq dep: https://github.com/falcosecurity/libs/pull/1500 Moreover, some fixes on the recently introduced async event queue class happened: https://github.com/falcosecurity/libs/pull/1490, https://github.com/falcosecurity/libs/pull/1504. Finally, some fixes around the stats code: https://github.com/falcosecurity/libs/pull/1505, https://github.com/falcosecurity/libs/pull/1506. Rumors have it coming next week: New big cleanup: deprecation of tracers: https://github.com/falcosecurity/libs/pull/1503 ppc64le support for bpf and kmod + CI build jobs: https://github.com/falcosecurity/libs/pull/1497 remove old metaevents implementation: https://github.com/falcosecurity/libs/pull/1495 Small fix on top of ia32 work: https://github.com/falcosecurity/libs/pull/1501 Second part of an effort by Luca Guerra to clean up libsinsp from potential undefined behavior: https://github.com/falcosecurity/libs/pull/1502. This is so important that deserved to be left alone :) Falco We have a new official adopter! Welcome to Thought Machine: https://github.com/falcosecurity/falco/pull/2919 Small cleanup to avoid Falco configuratiom to be inited twice: https://github.com/falcosecurity/falco/pull/2917 Falcoctl The new driver command was merged! https://github.com/falcosecurity/falcoctl/pull/343 We are now in the process of adding tests and eventually fixing spotted bugs :) Also, the new asset artifact type PR is being reviewed: https://github.com/falcosecurity/

## C Structure Padding Initialization

DevFeed: [C Structure Padding Initialization](<https://devfeed.tech/articles/c-structure-padding-initialization-47199.md>)

Original publisher: [Read original article](<https://interrupt.memfault.com/blog/c-struct-padding-initialization>)

Author: Noah Pendleton

Published: 2022-03-01T00:00:00Z

Content type: article

Language: en

Sources: [Interrupt](<https://devfeed.tech/sources/interrupt.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [structure](<https://devfeed.tech/topics/structure.md>), [clang](<https://devfeed.tech/topics/clang.md>), [gcc](<https://devfeed.tech/topics/gcc.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [cpu](<https://devfeed.tech/topics/cpu.md>)

Tags: [behavior](<https://devfeed.tech/tags/behavior.md>), [c](<https://devfeed.tech/tags/c.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [padding](<https://devfeed.tech/tags/padding.md>), [structure](<https://devfeed.tech/tags/structure.md>)

### AI overview

An exploration of C structure padding initialization, including alignment, compiler behavior in Clang and GCC, packed structures, performance overhead, type aliasing, and bitfields.

### Source excerpt

This article takes a look at a few different aspects of C structure initialization. In particular, we'll look at when it matters, the current state of things in Clang and GCC, recommendations, and the ✨ future ✨. Continue reading...

## Uninitialized Stack Variables

DevFeed: [Uninitialized Stack Variables](<https://devfeed.tech/articles/uninitialized-stack-variables-30260.md>)

Original publisher: [Read original article](<https://www.netmeister.org/blog/stack-vars.html>)

Published: 2021-11-25T03:46:08Z

Content type: article

Language: en

Sources: [Signs of Triviality](<https://devfeed.tech/sources/signs-of-triviality.md>)

Topics: [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>)

Tags: [behavior](<https://devfeed.tech/tags/behavior.md>), [illustration](<https://devfeed.tech/tags/illustration.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

An illustration explains how uninitialized stack variables can lead to undefined behavior.

### Source excerpt

An illustration of how uninitialized stack variables can lead to undefined behavior.

## Firmware Static Analysis with CodeChecker

DevFeed: [Firmware Static Analysis with CodeChecker](<https://devfeed.tech/articles/firmware-static-analysis-with-codechecker-47367.md>)

Original publisher: [Read original article](<https://interrupt.memfault.com/blog/static-analysis-with-codechecker>)

Author: François Baldassari

Published: 2021-05-19T00:00:00Z

Content type: tutorial

Language: en

Sources: [Interrupt](<https://devfeed.tech/sources/interrupt.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [Embedded Software Dev](<https://devfeed.tech/topics/embedded-software-dev.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [clang](<https://devfeed.tech/topics/clang.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Memory Leaks](<https://devfeed.tech/topics/memory-leaks.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Security](<https://devfeed.tech/topics/security.md>), [Open Source](<https://devfeed.tech/topics/open-source.md>), [Linux](<https://devfeed.tech/topics/linux.md>)

Tags: [cli](<https://devfeed.tech/tags/cli.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [configure](<https://devfeed.tech/tags/configure.md>), [false-positives](<https://devfeed.tech/tags/false-positives.md>), [firmware](<https://devfeed.tech/tags/firmware.md>), [go](<https://devfeed.tech/tags/go.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [linux](<https://devfeed.tech/tags/linux.md>), [memory-leaks](<https://devfeed.tech/tags/memory-leaks.md>), [pull-requests](<https://devfeed.tech/tags/pull-requests.md>), [security](<https://devfeed.tech/tags/security.md>), [software](<https://devfeed.tech/tags/software.md>), [static-analysis](<https://devfeed.tech/tags/static-analysis.md>)

### AI overview

A tutorial on setting up CodeChecker for firmware projects to perform C static analysis, track findings, manage false positives, and inspect issues introduced by code changes and pull requests.

### Source excerpt

In this post, I go over how to set up CodeChecker on a firmware project to reap the benefits of static analysis. I'll also cover ways to deal with false positives, and configure your assert functions to be analysis-friendly. Continue reading...

## Using Asserts in Embedded Systems

DevFeed: [Using Asserts in Embedded Systems](<https://devfeed.tech/articles/using-asserts-in-embedded-systems-47183.md>)

Original publisher: [Read original article](<https://interrupt.memfault.com/blog/asserts-in-embedded-systems>)

Author: Tyler Hoffman

Published: 2019-11-05T00:00:00Z

Content type: tutorial

Language: en

Sources: [Interrupt](<https://devfeed.tech/sources/interrupt.md>)

Topics: [Embedded Systems](<https://devfeed.tech/topics/embedded-systems.md>), [Embedded Software Dev](<https://devfeed.tech/topics/embedded-software-dev.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Code](<https://devfeed.tech/topics/code.md>), [Arm](<https://devfeed.tech/topics/arm.md>)

Tags: [arm](<https://devfeed.tech/tags/arm.md>), [code](<https://devfeed.tech/tags/code.md>), [debug](<https://devfeed.tech/tags/debug.md>), [embedded](<https://devfeed.tech/tags/embedded.md>), [embedded-systems](<https://devfeed.tech/tags/embedded-systems.md>), [firmware](<https://devfeed.tech/tags/firmware.md>), [memory-corruption](<https://devfeed.tech/tags/memory-corruption.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

A tutorial on using runtime asserts in embedded systems and firmware, including debug and production builds, postmortem data capture, and custom assert handling for ARM Cortex-M devices. It explains how asserts can expose bugs, undefined behavior, and memory corruption while keeping code-size usage low.

### Source excerpt

By using asserts proactively in embedded systems on debug and production builds, developers can both prevent more bugs before shipping and quickly surface and fix them after shipping. Proper assert handling is also the safest way to handle issues and undefined behavior that occur in production. In this post, we'll go over best practices with asserts, when to use asserts, and then come up with a production ready custom assert implementation for an ARM Cortex-M device, all while keeping the code size usage to a minimum. Continue reading...

## A Satirical LLVM Post About Undefined Behavior, Compiler Semantics, and Sanitizer Tools

DevFeed: [A Satirical LLVM Post About Undefined Behavior, Compiler Semantics, and Sanitizer Tools](<https://devfeed.tech/articles/my-little-llvm-undefined-behavior-is-magic-43030.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2016/04/undefined-behavior-is-magic.html>)

Author: JF Bastien and Michael Spencer

Published: 2016-04-01T00:00:00Z

Content type: opinion

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [clang](<https://devfeed.tech/topics/clang.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Security](<https://devfeed.tech/topics/security.md>)

Tags: [april-1](<https://devfeed.tech/tags/april-1.md>), [april-fools](<https://devfeed.tech/tags/april-fools.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compilers](<https://devfeed.tech/tags/compilers.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [sanitizer](<https://devfeed.tech/tags/sanitizer.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>), [x86](<https://devfeed.tech/tags/x86.md>)

### AI overview

A satirical LLVM post discusses undefined behavior, compiler semantics, C++ memory and arithmetic rules, and sanitizer tools through fictional rebranding and deliberately absurd proposed features.

### Source excerpt

There's been lots of discussion online (and then quite some more) about compilers abusing undefined behavior. As a response the LLVM compiler infrastructure is rebranding and adopting a motto to make undefined behavior friendlier and less prone to corruption. The re-branding puts to rest a long-standing issue with LLVM's "dragon" logo actually being a wyvern with an upside-down head, a special form of undefined behavior in its own right. The logo is now clearly a pegasus pony. Another great side-effect of this rebranding is increased security by auto-magically closing all vulnerabilities used by the hacker who goes by the pseudonym "Pinkie Pie". These new features are enabled with the -rainbow clang option, in honor of Rainbow Dash's unary name. A Few Examples C++'s memory model specifies that data races are undefined behavior. It is well established that no sane compiler would optimize atomics, LLVM will therefore supplement the Standard's happens-before relationship with an LLVM-specific happens-to-work relationship. On most architectures this will be implemented with micro-pause primitives such as x86's rep rep rep nop instruction. Shifts by bit-width or larger will now return a normally-distributed random number. This also obsoletes rand() and std::random_shuffle. bool now obeys the rules of truthiness to avoid that annoying "but what if it's not zero or one?" interview question. Further, incrementing a bool with ++ now does the right thing. Atomic integer arithmetic is already specified to be two's complement. Regular arithmetic will therefore now also be atomic. Except when volatile, but not when volatile atomic. NaNs will now compare equal, subnormals are free to self-classify as normal / zero / other, negative zero simply won't be a thing, IEEE-754 has been upgraded to PONY-754, floats will still round with style, and generating a signaling NaN is now guaranteed to not be quiet by being equivalent to putchar('\a'). While we're at it none of math.h will set e

## LLVM Weekly - #109, Feb 1st 2016

DevFeed: [LLVM Weekly - #109, Feb 1st 2016](<https://devfeed.tech/articles/llvm-weekly-109-feb-1st-2016-43016.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2016/02/llvm-weekly-109-feb-1st-2016.html>)

Author: Alex Bradbury

Published: 2016-02-01T06:24:00Z

Content type: news

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [clang](<https://devfeed.tech/topics/clang.md>), [CMake](<https://devfeed.tech/topics/cmake.md>), [JIT](<https://devfeed.tech/topics/jit.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Firefox](<https://devfeed.tech/topics/firefox.md>), [C](<https://devfeed.tech/topics/c.md>), [Framework](<https://devfeed.tech/topics/framework.md>), [MSVC](<https://devfeed.tech/topics/msvc.md>), [WebAssembly](<https://devfeed.tech/topics/web-assembly.md>), [Chromium](<https://devfeed.tech/topics/chromium.md>)

Tags: [chromium](<https://devfeed.tech/tags/chromium.md>), [clang](<https://devfeed.tech/tags/clang.md>), [clang-cl](<https://devfeed.tech/tags/clang-cl.md>), [cmake](<https://devfeed.tech/tags/cmake.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [jit](<https://devfeed.tech/tags/jit.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvmweekly](<https://devfeed.tech/tags/llvmweekly.md>), [news](<https://devfeed.tech/tags/news.md>), [release](<https://devfeed.tech/tags/release.md>), [undefined-behaviour](<https://devfeed.tech/tags/undefined-behaviour.md>)

### AI overview

LLVM Weekly issue 109 reports developments across LLVM and related projects, including Sulong's LLVM IR interpreter and JIT compilation, building Firefox with clang-cl, the removal of LLVM's autoconf build system in favor of CMake, discussions about Clang atomics and LLVM IR memory scopes, and compiler optimizations and commits.

### Source excerpt

Welcome to the one hundred and ninth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by Alex Bradbury. Subscribe to future issues at http://llvmweekly.org and pass it on to anyone else you think may be interested. Please send any tips or feedback to asb@asbradbury.org, or @llvmweekly or @asbradbury on Twitter. The canonical home for this issue can be found here at llvmweekly.org. News and articles from around the web The GNU Tools Cauldron 2016 has been announced for the 9th-11th of September 2016, in Hebden Bridge, UK. The Sulong project has been announced. It is an LLVM IR interpreter using the Truffle framework and Graal on the JVM to support JIT compilation. Ehsan Akhgari has posted an updated on building Firefox with clang-cl. It is now possible to build a complete Firefox with Clang without using the MSVC fallback once. I've mentioned it down below in the list of notable commits, but it's worth calling out here too: the old autoconf build-system has now been removed from LLVM. 3.8 will be the last release to include it. Time to switch to CMake if you haven't already. John Regehr gave a talk about undefined behaviour in LLVM at the Paris LLVM meetup, and you can find the slides here. On the mailing lists James Knight has written to the list to get feedback on approaches to cleaning up Clang's handling of atomics. There seems to be widespread support for the cleanup. James followed up again to slightly revise his plan. Matt Arsenault proposes that all libcalls be canonicalized to intrinsics. All responses so far are in favour. Ke Bai has shared a proposal on representing multiple memory scopes in LLVM IR. There hasn't been any feedback yet. Dmitree Kuvaiskii asks if anyone has implemented a pass utilizing Intel's new MPX memory protection. The answer appears to be no, and in addition David and Kostya are sceptical about how worthwhile it would be. Peter C

## LLVM Weekly - #78, June 29th 2015

DevFeed: [LLVM Weekly - #78, June 29th 2015](<https://devfeed.tech/articles/llvm-weekly-78-june-29th-2015-42981.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2015/06/llvm-weekly-78-june-29th-2015.html>)

Author: Alex Bradbury

Published: 2015-06-29T03:51:00Z

Content type: news

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [clang](<https://devfeed.tech/topics/clang.md>), [C](<https://devfeed.tech/topics/c.md>), [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [CMake](<https://devfeed.tech/topics/cmake.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [RISC-V](<https://devfeed.tech/topics/riscv.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [standard](<https://devfeed.tech/topics/standard.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [clang](<https://devfeed.tech/tags/clang.md>), [cmake](<https://devfeed.tech/tags/cmake.md>), [debug](<https://devfeed.tech/tags/debug.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [llvmweekly](<https://devfeed.tech/tags/llvmweekly.md>), [risc-v](<https://devfeed.tech/tags/risc-v.md>), [standard](<https://devfeed.tech/tags/standard.md>), [testing](<https://devfeed.tech/tags/testing.md>)

### AI overview

Issue 78 of LLVM Weekly reports on the LLVM/Clang 3.7 release plan, a C survey, the LLVM/Clang 3.6.2 release candidate, and mailing-list proposals concerning debugging, boolean evaluation, CMake target testing, and undefined behavior.

### Source excerpt

Welcome to the seventy-eighth issue of LLVM Weekly, a weekly newsletter (published every Monday) covering developments in LLVM, Clang, and related projects. LLVM Weekly is brought to you by Alex Bradbury. Subscribe to future issues at http://llvmweekly.org and pass it on to anyone else you think may be interested. Please send any tips or feedback to asb@asbradbury.org, or @llvmweekly or @asbradbury on Twitter. I'm in the Bay Area this week for the second RISC-V workshop where my colleague and I will of course be talking about lowRISC. If you're not able to make it, keep an eye on the lowRISC blog which I intend to keep updating semi-live with notes from the talks and presentations. The canonical home for this issue can be found here at llvmweekly.org. News and articles from around the web Hans Wennborg has shared the release plan for LLVM/Clang 3.7. This would see the release branch created on 14th July, with a final release targeted for 21st August. A detailed analysis of the results of the "What is C in practice" survey has now been posted. The survey gained around 300 responses, and aims to help guide the definition of a formal model for the de facto standard of C (i.e. C as it is used rather than purely as specified in the ISO standard). The 3.6.2-rc1 LLVM/Clang release has been tagged. As always, testing is encouraged. On the mailing lists Unfortunately at the time of writing GMANE seems to be having some problems, so for this week I'll be using links to the pipermail archives of the relevant mailing list posts. Adrian Prantl has a proposal for improving the quality of debug locations and of DbgValueHistoryCalculator. This will involve adding new heuristics so DbgValueHistoryCalculator is smarter at creating ranges. Sanjoy Patel kicked off a discussion about conversion between bitwise AND and short-circuit evaluation for booleans. In particularly, he's wanting to ensure that short circuit evaluation is not used (though as is pointed out in the thread, the benef

## Testing libc++ with -fsanitize=undefined

DevFeed: [Testing libc++ with -fsanitize=undefined](<https://devfeed.tech/articles/testing-libc-with-fsanitize-undefined-42881.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2013/04/testing-libc-with-fsanitizeundefined.html>)

Author: Marshall Clow

Published: 2013-04-01T10:12:00Z

Content type: tutorial

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [Software Testing](<https://devfeed.tech/topics/software-testing.md>), [clang](<https://devfeed.tech/topics/clang.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>)

Tags: [built-from-source](<https://devfeed.tech/tags/built-from-source.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [integer-overflow](<https://devfeed.tech/tags/integer-overflow.md>), [sanitizer](<https://devfeed.tech/tags/sanitizer.md>), [testing](<https://devfeed.tech/tags/testing.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

This article explains testing libc++ with Clang's Undefined Behavior Sanitizer (UBSan). It describes enabling UBSan in the compiler and linker, building compatible libc++ and libc++abi libraries from source, and the test results, including runtime errors and failing tests.

### Source excerpt

[This article is re-posted in a slightly expanded form from Marshall's blog] After my last article, Testing libc++ with Address Sanitizer, I thought "what other tests can I run?" Address Sanitizer (ASan) is not the only "sanitizer" that clang offers. There are "Thread Sanitizer" (TSan), "Undefined Behavior Sanitizer" (UBSan), and others. There's an integer overflow sanitizer which is called IOC coming in the 3.3 release of clang. The documentation for UBSan can be found on the LLVM site. I have been looking at the results of running the libc++ test suite with UBSan enabled. Even if you're not interested in libc++ specifically, this post can be a useful introduction to useful Clang bug detectors, and shows several classes of problems they can find. The mechanicsLike ASan, UBSan is a compiler pass and a custom runtime library. You enable this by passing -fsanitize=undefined to the compiler and linker. I ran the libc++ test suite like this: cd $LLVM/libcxx/test CC=/path/to/tot/clang OPTIONS="--std=c++11 -stdlib=libc++ -fsanitize=undefined" ./testit Unfortunately, this failed; working with unreleased compilers and libraries, I needed updated versions of both libc++.dylib and libc++abi.dylib. So I built those from sources, and then used DYLD_LIBRARY_PATH to make sure that the test program used the libraries that I'd just built. (I didn't want to replace the ones in /usr/lib, because lots of things in the system depend on them) cd $LLVM/libcxx/test DYLD_LIBRARY_PATH=$LLVM/libcxx/lib:$LLVM/libcxxabi/lib CC=/path/to/tot/clang OPTIONS="-std=c++11 -stdlib=libc++ -fsanitize=undefined -L $LLVM/libcxxabi/lib -lc++abi" ./testit where, as before "/path/to/tot/clang" is the clang that I just built from source, and $LLVM is where I've checked out the various parts of LLVM from Subversion. The resultsAnd the tests were off and running. In the last article, I noted that these tests take about 30 minutes to run on my MacBook Pro. The ASan tests took about 90 minutes. I was pleasantly s

## What Every C Programmer Should Know About Undefined Behavior #3/3

DevFeed: [What Every C Programmer Should Know About Undefined Behavior #3/3](<https://devfeed.tech/articles/what-every-c-programmer-should-know-about-undefined-behavior-3-3-42863.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_21.html>)

Author: Chris Lattner

Published: 2011-05-21T00:48:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [clang](<https://devfeed.tech/topics/clang.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [bug](<https://devfeed.tech/topics/bug.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [c](<https://devfeed.tech/tags/c.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

This article examines why compilers cannot always warn when C undefined behavior enables optimizations. It discusses warning usefulness, false positives, compiler layering, LLVM IR, type-based alias analysis, and Clang's handling of simple undefined-behavior cases.

### Source excerpt

In Part 1 of the series, we took a look at undefined behavior in C and showed some cases where it allows C to be more performant than "safe" languages. In Part 2, we looked at the surprising bugs this causes and some widely held misconceptions that many programmers have about C. In this article, we look at the challenges that compilers face in providing warnings about these gotchas, and talk about some of the features and tools that LLVM and Clang provide to help get the performance wins, while taking away some of the surprise. Translation available in: Japanese Why can't you warn when optimizing based on undefined behavior? People often ask why the compiler doesn't produce warnings when it is taking advantage of undefined behavior to do an optimization, since any such case might actually be a bug in the user code. The challenges with this approach are that it is 1) likely to generate far too many warnings to be useful - because these optimizations kick in all the time when there is no bug, 2) it is really tricky to generate these warnings only when people want them, and 3) we have no good way to express (to the user) how a series of optimizations combined to expose the opportunity being optimized. Lets take each of these in turn: It is "really hard" to make it actually useful Lets look at an example: even though invalid type casting bugs are frequently exposed by type based alias analysis, it would not be useful to produce a warning that "the optimizer is assuming that P and P[i] don't alias" when optimizing "zero_array" (from Part #1 of our series). float *P; void zero_array() { int i; for (i = 0; i < 10000; ++i) P[i] = 0.0f; } Beyond this "false positive" problem, a logistical problem is that the optimizer doesn't have enough information to generate a reasonable warning. First of all, it is working on an already-abstract representation of the code (LLVM IR) which is quite different from C, and second, the compiler is highly layered to the point where the optimiza

## What Every C Programmer Should Know About Undefined Behavior #2/3

DevFeed: [What Every C Programmer Should Know About Undefined Behavior #2/3](<https://devfeed.tech/articles/what-every-c-programmer-should-know-about-undefined-behavior-2-3-42862.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html>)

Author: Chris Lattner

Published: 2011-05-14T12:33:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [C](<https://devfeed.tech/topics/c.md>), [undefined\_behavior](<https://devfeed.tech/topics/undefined-behavior.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [bug](<https://devfeed.tech/topics/bug.md>), [Linux Kernel](<https://devfeed.tech/topics/linux-kernel.md>)

Tags: [bug](<https://devfeed.tech/tags/bug.md>), [c](<https://devfeed.tech/tags/c.md>), [clang](<https://devfeed.tech/tags/clang.md>), [code](<https://devfeed.tech/tags/code.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [linux-kernel](<https://devfeed.tech/tags/linux-kernel.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

### AI overview

This article explains how undefined behavior in C and C++ enables compiler optimizations but can produce surprising results. It examines how optimization order, null-check elimination, dead-code elimination, and inlining can change code behavior, including an example based on an exploitable Linux kernel bug.

### Source excerpt

In Part 1of our series, we discussed what undefined behavior is, and how it allows C and C++ compilersto produce higher performance applications than "safe" languages. This post talks about how"unsafe" C really is, explaining some of the highly surprising effects that undefined behaviorcan cause. In Part#3, we talk about what friendly compilers can do to mitigate some of the surprise, evenif they aren't required to. I like to call this "Why undefined behavior is often a scary and terrible thing for Cprogrammers". :-) Translation available in: Japanese,and Spanisha>.Interacting Compiler Optimizations Lead to Surprising Results A modern compiler optimizer contains many optimizations that are run in specific orders, sometimes iterated, and change as the compiler evolves over time (e.g. new releases come out). Also, different compilers often have substantially different optimizers. Because optimizations run at different stages, emergent effects can occur due to previous optimizations changing the code. Lets take a look at a silly example (simplified from an exploitable bug that was found in the Linux Kernel) to make this more concrete: void contains_null_check(int *P) { int dead = *P; if (P == 0) return; *P = 4; } In this example, the code "clearly" checks for the null pointer. If the compiler happens to run "Dead Code Elimination" before a "Redundant Null Check Elimination" pass, then we'd see the code evolve in these two steps: void contains_null_check_after_DCE(int *P) { //int dead = *P; // deleted by the optimizer. if (P == 0) return; *P = 4; } and then: void contains_null_check_after_DCE_and_RNCE(int *P) { if (P == 0) // Null check not redundant, and is kept. return; *P = 4; } However, if the optimizer happens to be structured differently, it could run RNCE before DCE. This would give us these two steps: void contains_null_check_after_RNCE(int *P) { int dead = *P; if (false) // P was dereferenced by this point, so it can't be null return; *P = 4; } and then dead co

[Next page](<https://devfeed.tech/topics/undefined-behavior.md?cursor=WyIyMDExLTA1LTE0VDEyOjMzOjAwKzAwOjAwIiwgImY4ZTBiYmMxLTE2YTAtNGI3MS1iODE2LTg2MjVhOWI4N2JlMyJd>)