Skip to content

UBSAN failures in clang constant interpreter tests on 32 bit ARM #94741

Open
@DavidSpickett

Description

@DavidSpickett

Doing a 32 bit Arm build with UBSAN enabled, I get many failures from the clang interpreter:

  Clang :: AST/Interp/arrays.cpp
  Clang :: AST/Interp/atomic.c
  Clang :: AST/Interp/atomic.cpp
  Clang :: AST/Interp/bitfields.cpp
  Clang :: AST/Interp/builtin-align-cxx.cpp
  Clang :: AST/Interp/builtin-functions.cpp
  Clang :: AST/Interp/builtins.cpp
  Clang :: AST/Interp/c.c
  Clang :: AST/Interp/c23.c
  Clang :: AST/Interp/comma.cpp
  Clang :: AST/Interp/complex.c
  Clang :: AST/Interp/complex.cpp
  Clang :: AST/Interp/cond.cpp
  Clang :: AST/Interp/const-eval.c
  Clang :: AST/Interp/const-fpfeatures.cpp
  Clang :: AST/Interp/constexpr-nqueens.cpp
  Clang :: AST/Interp/constexpr-subobj-initialization.cpp
  Clang :: AST/Interp/cxx03.cpp
  Clang :: AST/Interp/cxx11.cpp
  Clang :: AST/Interp/cxx17.cpp
  Clang :: AST/Interp/cxx20.cpp
  Clang :: AST/Interp/cxx23.cpp
  Clang :: AST/Interp/cxx98.cpp
  Clang :: AST/Interp/depth-limit.cpp
  Clang :: AST/Interp/enums-targets.cpp
  Clang :: AST/Interp/enums.cpp
  Clang :: AST/Interp/eval-order.cpp
  Clang :: AST/Interp/floats.cpp
  Clang :: AST/Interp/functions.cpp
  Clang :: AST/Interp/if.cpp
  Clang :: AST/Interp/intap.cpp
  Clang :: AST/Interp/invalid.cpp
  Clang :: AST/Interp/lambda.cpp
  Clang :: AST/Interp/lifetimes.cpp
  Clang :: AST/Interp/literals.cpp
  Clang :: AST/Interp/loops.cpp
  Clang :: AST/Interp/memberpointers.cpp
  Clang :: AST/Interp/nullable.cpp
  Clang :: AST/Interp/objc.mm
  Clang :: AST/Interp/opencl.cl
  Clang :: AST/Interp/pointer-addition.c
  Clang :: AST/Interp/records.cpp
  Clang :: AST/Interp/references.cpp
  Clang :: AST/Interp/shifts.cpp
  Clang :: AST/Interp/spaceship.cpp
  Clang :: AST/Interp/switch.cpp
  Clang :: AST/Interp/sycl.cpp
  Clang :: AST/Interp/unions.cpp
  Clang :: AST/Interp/vectors.cpp
  Clang :: AST/Interp/weak.cpp

Most of them are problems with reference binding or calling of constructors on misaligned addresses. Usually the type requires 8 byte alignment but the address is 4 byte aligned.

RUN: at line 1: /home/david.spickett/build-llvm-arm/bin/clang -cc1 -internal-isystem /home/david.spickett/build-llvm-arm/lib/clang/19/include -nostdsysteminc -fexperimental-new-constant-interpreter -verify=expected,both /home/david.spickett/llvm-project/clang/test/AST/Interp/arrays.cpp
+ /home/david.spickett/build-llvm-arm/bin/clang -cc1 -internal-isystem /home/david.spickett/build-llvm-arm/lib/clang/19/include -nostdsysteminc -fexperimental-new-constant-interpreter -verify=expected,both /home/david.spickett/llvm-project/clang/test/AST/Interp/arrays.cpp
/home/david.spickett/llvm-project/clang/lib/AST/Interp/InterpStack.h:36:35: runtime error: constructor call on misaligned address 0xe7cff014 for type 'clang::interp::Pointer', which requires 8 byte alignment
0xe7cff014: note: pointer points here
  3c f0 cf e7 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/david.spickett/llvm-project/clang/lib/AST/Interp/InterpStack.h:36:35 in

This has come up a lot recently, including #89811 which has "uncovered" this issue outside of UBSAN builds.

I think the assumptions in the interpreter's management of its virtual stack do not hold for 32 bit Arm. I don't know that that's the cause of all the issues we have seen without UBSAN, but it seems likely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions