Skip to content

Commit

Permalink
Set internal linkage on groupshared variables; check if function is d…
Browse files Browse the repository at this point in the history
…efined
  • Loading branch information
hekota committed Jun 7, 2024
1 parent a245ec6 commit ca6242e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ def FunctionTmpl

def HLSLEntry
: SubsetSubject<Function,
[{S->isExternallyVisible() && !isa<CXXMethodDecl>(S)}],
[{S->getDeclContext()->getRedeclContext()->isFileContext() &&
S->getStorageClass() != SC_Static}],
"global functions">;

def HLSLBufferObj : SubsetSubject<HLSLBuffer,
[{isa<HLSLBufferDecl>(S)}],
"cbuffer/tbuffer">;
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
// - a variable, variable template, function, or function template
// that is explicitly declared static; or
// (This bullet corresponds to C99 6.2.2p3.)
// - also applies to HLSL
return LinkageInfo::internal();
}

Expand Down Expand Up @@ -657,6 +658,11 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
if (PrevVar->getStorageClass() == SC_Static)
return LinkageInfo::internal();
}

if (Context.getLangOpts().HLSL &&
Var->hasAttr<HLSLGroupSharedAddressSpaceAttr>())
return LinkageInfo::internal();

} else if (const auto *IFD = dyn_cast<IndirectFieldDecl>(D)) {
// - a data member of an anonymous union.
const VarDecl *VD = IFD->getVarDecl();
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/CodeGen/CGHLSLRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,10 @@ void CGHLSLRuntime::emitFunctionProlog(const FunctionDecl *FD,
if (FD->hasAttr<HLSLShaderAttr>()) {
emitEntryFunction(FD, Fn);
} else {
// HLSL functions that are not shader entry points or exported
// have internal linkage by default.
// FIXME: skip this for exported functions (Issue #92812)
Fn->setLinkage(GlobalValue::InternalLinkage);
// HLSL functions defined in the current translation unit that are not
// shader entry points or exported have internal linkage by default.
if (FD->isDefined())
Fn->setLinkage(GlobalValue::InternalLinkage);
}
}

Expand Down

0 comments on commit ca6242e

Please sign in to comment.