[PATCH] D126324: [clang] Allow const variables with weak attribute to be overridden
Anders Waldenborg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 24 13:36:44 PDT 2022
wanders created this revision.
wanders added reviewers: lattner, jyknight, rsmith.
wanders added a project: clang.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
wanders requested review of this revision.
Herald added a subscriber: cfe-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D126324
Files:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/global-init.c
clang/test/CodeGen/weak_constant.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126324.431776.patch
Type: text/x-patch
Size: 5594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220524/455198fe/attachment.bin>
More information about the cfe-commits
mailing list