[all-commits] [llvm/llvm-project] dd2362: [clang] Allow const variables with weak attribute ...

Anders Waldenborg via All-commits all-commits at lists.llvm.org
Fri Jun 3 14:46:36 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dd2362a8bab312dffc42bfcb30ad1340840ef581
      https://github.com/llvm/llvm-project/commit/dd2362a8bab312dffc42bfcb30ad1340840ef581
  Author: Anders Waldenborg <anders at 0x63.nu>
  Date:   2022-06-03 (Fri, 03 Jun 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/AttrDocs.td
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/test/CodeGen/global-init.c
    M clang/test/CodeGen/weak_constant.c

  Log Message:
  -----------
  [clang] Allow const variables with weak attribute to be overridden

A variable with `weak` attribute signifies that it can be replaced with
a "strong" symbol link time. Therefore it must not emitted with
"weak_odr" linkage, as that allows the backend to use its value in
optimizations.

The frontend already considers weak const variables as
non-constant (note_constexpr_var_init_weak diagnostic) so this change
makes frontend and backend consistent.

This commit reverses the
  f49573d1 weak globals that are const should get weak_odr linkage.
commit from 2009-08-05 which introduced this behavior. Unfortunately
that commit doesn't provide any details on why the change was made.

This was discussed in
https://discourse.llvm.org/t/weak-attribute-semantics-on-const-variables/62311

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




More information about the All-commits mailing list