Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

A new constant expression interpreter for Clang, Part 3

October 22, 2024
Timm Baeder
Related topics:
C, C#, C++Developer tools
Related products:
Red Hat Enterprise Linux

    Before we start, here are the previous parts: Part 1 and Part 2.

    Commits since last time

    My last article was published on October 11th, so let's check the commits since then:

    $ git log --after=2023-09-11 | grep -i "\[clang\]\[Interp\]" | wc -l
    $ 717
    $ git log --after=2023-09-11 | grep -i "\[clang\]\[bytecode\]" | wc -l
    $ 57

    The second count is needed because I renamed the directory the constant interpreter lives in from Interp/ to ByteCode/ and the new convention is to tag commits with [clang][bytecode].

    The 774 commits in the last year is quite a step up from the 308 commits from the previous year. We agreed to switch to a post-commit review system for the new constant-interpreter, so I can be more productive without clogging up review queues upstream.

    Detailed changes

    This year, Yihan Wang contributed several commits, including the support for binary and unary operations on vectors.

    The full list of changes includes:

    • Support for variadic functions.

    • Support for more builtin functions: __builtin_parity, __builtin_clrsb, __builtin_bitreverse, __builtin_classify_type, __builtin_expect, __builtin_rotate{right,left}, __builtin_ffs, __builtin_addressof, __builtin_move(etc.), __builtin_eh_return_data_regno, __builtin_launder, various overflow and carry builtins, __builtin_clz, __builtin_ctz, __builtin_bswap, __builtin_vectorelements, __builtin_is_aligned, __builtin_align_up, __builtin_align_down, __builtin_os_log_format_buffer_size, __builtin_convertvector, __builtin_shufflevector, __builtin_sycl_unique_stable_name, __noop, etc.

    • Support for _Complex types, including multiplication, division, and support for integral complex types.

    • Support for C++23 [[assume]].

    • Support for __datasizeof and vec_step

    • Nullability attributes on function parameters.

    • Support for vectors: initializing from various expression types, unary operators, comparison operators.

    • Support for functions with explicit instance parameters.

    • Support for unions, including changing the active member.

    • Support for member pointers.

    • Support for statement expressions.

    • Improved support for virtual base classes.

    • Dynamic memory allocation, i.e., new and delete as well as __builtin_operator_new and __builtin_operator_delete.

    • Support for virtual function calls with covariant return types.

    • Support for ObjectiveC blocks.

    Not listed are tons of correctness fixes, improvements to diagnostic output, and support for lots of new expression and statement types.

    Wider testing

    The bytecode interpreter has its own set of tests located in test/AST/ByteCode/. Those tests usually run the same file with the current interpreter and the new bytecode interpreter and compare their outputs. Ideally, they output the same diagnostics and accept or reject the same constant expressions.

    In early 2024, I started to additionally run the entire clang test suite (i.e. ninja check-clang) with the bytecode interpreter. I'm tracking the results over time here. See Figure 1.

    A graph depicting failures in the clang test suite since April 2024
    Figure 1: Failures in the clang test suite since April 2024.

    This results in much better testing coverage. Not only do I have a better overview of the overall state of the bytecode interpreter, but I also run every commit I make through the entire clang testsuite first and check for unexpected regressions.

    Unfortunately some of the test files (especially test/SemaCXX/constant-expression-cxx{11,14, ...}) are rather big and test a ton of things, but they still only count as one test case in the graph above. For example, test/SemaCXX/constant-expression-cxx11.cpp currently fails and generates 143 errors. Fixing these bigger files is a lot of work and only progresses slowly.

    Next steps

    Apart from the known bugs, there are a few bigger things still missing in the bytecode interpreter:

    • Support for fixed point types

    • Support for __builtin_bit_cast. I have an old PR for this, which unfortunately went nowhere since it was requested to support bit casts of bit fields as well. This is something the current interpreter does not support. I plan on implementing this by copying the contents of a Pointer to a byte buffer, and use the same code path to implement __builtin_memcmp, etc.

    • Support for array fillers. When allocating large arrays with mostly or all default-constructed elements, it is useful to only allocate the elements that are actually used.

    • Support for typeid pointers

    Almost all points in the list above are a lot of work, some probably require bigger refactorings to the internals of the bytecode interpreter.

    Related Posts

    • Profile-guided optimization in Clang: Dealing with modified sources

    • Support lifecycle for Clang/LLVM, Go, and Rust in Red Hat Enterprise Linux 8

    • Use compiler flags for stack protection in GCC and Clang

    • Customize the compilation process with Clang: Optimization options

    • Write toolchain-agnostic RPM spec files for GCC and Clang

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    What’s up next?

    Download the Advanced Linux Commands cheat sheet. You'll learn to manage applications and executables in a Linux operating system, define search criteria and query audit logs, set and monitor network access, and more.

    Get the cheat sheet
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI