Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linkage of weak function declarations #428

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/vast/Dialect/Core/Linkage.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Dialect/Core/Linkage.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (17, 22.04)

Run clang-format on lib/vast/Dialect/Core/Linkage.cpp

File lib/vast/Dialect/Core/Linkage.cpp does not conform to Custom style guidelines. (lines 169, 170)

#include <vast/Dialect/Core/Linkage.hpp>

Expand Down Expand Up @@ -162,19 +162,24 @@
return GlobalLinkageKind::InternalLinkage;
}

if (const auto *fn = decl->getAsFunction()) {
if (fn->isMultiVersion() && linkage == clang::GVA_AvailableExternally) {
return GlobalLinkageKind::LinkOnceAnyLinkage;
}
if (!fn->isThisDeclarationADefinition()
&& decl->hasAttr< clang::WeakAttr >())
{
return GlobalLinkageKind::ExternalWeakLinkage;
}
}

if (decl->hasAttr< clang::WeakAttr >()) {
if (is_constant)
return GlobalLinkageKind::WeakODRLinkage;
else
return GlobalLinkageKind::WeakAnyLinkage;
}

if (const auto *fn = decl->getAsFunction()) {
if (fn->isMultiVersion() && linkage == clang::GVA_AvailableExternally) {
return GlobalLinkageKind::LinkOnceAnyLinkage;
}
}

// We are guaranteed to have a strong definition somewhere else,
// so we can use available_externally linkage.
if (linkage == clang::GVA_AvailableExternally) {
Expand Down
2 changes: 1 addition & 1 deletion test/vast/Dialect/HighLevel/attr-d.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// CHECK: hl.func @fun weak () -> !hl.void {
void __attribute__((__weak__)) fun (void) {}
int mian() {
int main() {
fun();
return 0;
}