Other · Developers · Emerging

Developers struggle with the implications of undefined behavior (UB) in programming languages, leading to confusion and potential errors in code

Undefined behavior in compilers can lead to unexpected outcomes and difficulties in reasoning about code, causing frustration among developers.

Who experiences it: Developers

Momentum

0%

Pain

75

Competition

90

Opportunity

57/100

Signals over time

4 observed signals across 1 sources, tracked for 5 days. Confidence: low.

What people are saying Observed

  • “First we need to reduce the UB zoo because the types of UB in the C standard go all over the place (from "no newline at end of file" to "oops, this specific UB combined with this specific code leaks execution into the next function"). Also AFAIK the point where UB causes 'runtime disruption' is way after the C frontend in the optimizer passes, e.g. much too late for issuing compilation warnings even if the UB situation could be detected (because as far as I understand the problem, the breakage happens mainly because of unexpected 'spooky actions at a distance' between different optimizer passes, e.g. a specific optimizer pass doesn't even notice that it broke the code). You can get runtime errors for a lot of serious UB problems via UBSAN though of course (at the cost of some performance).”

    Hacker News · complaint

  • “I frankly find the situation around UB puzzling. AFAICT the idea was born in the times of very anemic compilers which would translate things that don't make definite sense, or work unpredictably on certain architectures. But why is it still a thing now, 50 years later? If a compiler can detect UB, I think the only reasonable way for it is to have the program terminate immediately, not release "nasal demons". (And, of course, many bugs get smashed against the -Wall which should be the default.) Of course, not all UB can be detected at compile time, like reading the padding bytes in a struct mentioned in the article. I wish there was a way to opt out of all UB, in an arbitrary but predictable way (an immediate crash would be fine), something like -fsanitize but for any UB at all that might happen at runtime. In quite some important code, I'd agree to tolerate the performance hit, it may be cheaper than dealing with the aftermath or an RCE exploited. I see that it's not entirely realistic though.”

    Hacker News · wishlist

  • “This isn’t a good mental model. The compiler isn’t limited to just affecting the code after the undefined behavior. It is allowed to assume undefined behavior never happens for the entire program . For example, this code with an improper guard: if (!p) puts("error"); printf("%d", *p); Since the program dereferences p in line 2, and dereferencing null is UB, the compiler is allowed to assume p is never null, so it’s allowed to delete line 1, even though it would have executed before the point where UB would happen. Even worse, the compiler isn't just allowed to not do things you told it to do, it's also allowed to do anything too.”

    Hacker News · frustration

  • “> The only insane thing about UB is that compiler writers took what everyone understand meant "the compiler emits what it emits and you get what you get" and turned it into "since it's undefined it means it can never happen so we can delete your null check". IMO UB as "undefined but don't be crazy please" was the original meaning of the standard but people argue on that. It is a fact that compilers didn't exploit UB as strongly back then. However there is a good reason for this change: if you want formal semantics (which you do want, at least possibly) it is pretty much impossible to distinguish the two. If "undefined behavior" is undefined in the math sense, or in formal semantics of languages - the operation can reach any Abstract Machine state, then the fact that you cannot reason about anything follows immediately. The only dubious thing is time-travel, and this was indeed removed in the last version of the standard (and also for Rust now).”

    Hacker News · frustration

Why now? AI inference

Existing solutions Observed

  • Valgrind · free · complaints: Can slow down program execution significantly, May require additional setup for certain environments, Not all types of undefined behavior are detected
  • Clang · free · complaints: Can be complex to configure for beginners, Some features may not be as mature as GCC, Error messages can be cryptic at times
  • GCC (GNU Compiler Collection) · free · complaints: Longer compilation times compared to some alternatives, Error messages can be difficult to interpret, Older versions may lack support for newer language features
  • AddressSanitizer · free (part of LLVM and GCC) · complaints: May not catch all types of undefined behavior, Can increase binary size, Requires recompilation with specific flags
  • Cppcheck · free · complaints: May produce false positives, Limited support for certain C++ features, User interface can be less intuitive

While existing tools like Valgrind and AddressSanitizer help detect undefined behavior, they often have limitations in coverage and usability, leading to confusion among developers. There is an opportunity for a more user-friendly solution that effectively addresses undefined behavior with clear diagnostics and minimal setup, targeting developers who struggle with the complexities of existing tools.

See the full evidence, competitor gap matrix and opportunity report.

Free account. No credit card.