[all-commits] [llvm/llvm-project] 13dd65: Do not create LLVM IR `constant`s for objects with...

Momchil Velikov via All-commits all-commits at lists.llvm.org
Mon May 24 14:05:45 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 13dd65b3a1a3ac049b5f3a9712059f7c61649bea
      https://github.com/llvm/llvm-project/commit/13dd65b3a1a3ac049b5f3a9712059f7c61649bea
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2021-05-24 (Mon, 24 May 2021)

  Changed paths:
    M clang/lib/Sema/SemaDecl.cpp
    A clang/test/CodeGenCXX/clang-sections-1.cpp
    A clang/test/CodeGenCXX/const-dynamic-init.cpp

  Log Message:
  -----------
  Do not create LLVM IR `constant`s for objects with dynamic initialisation

When a const-qualified object has a section attribute, that
section is set to read-only and clang outputs a LLVM IR constant
for that object. This is incorrect for dynamically initialised
objects.

For example:

    int init() { return 15; }

    __attribute__((section("SA")))
    const int a = init();

a is allocated to a read-only section and is left
unintialised (zero-initialised).

This patch adds checks if an initialiser is a constant expression
and allocates objects to sections as follows:

* const-qualified objects
  - no initialiser or constant initialiser: .rodata
  - dynamic initializer: .bss
* non const-qualified objects
  - no initialiser or dynamic initialiser: .bss
  - constant initialiser: .data

(".rodata", ".data", and ".bss" names used just for explanatory
purpose)

Differential Revision: https://reviews.llvm.org/D102693




More information about the All-commits mailing list