mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-24 14:56:48 +00:00
[CUDA][HIP][OpenMP] Emit deferred diagnostics by a post-parsing AST travese
This patch removes the explicit call graph for CUDA/HIP/OpenMP deferred diagnostics generated during parsing since it is error prone due to incomplete information about function declarations during parsing. In stead, this patch does a post-parsing AST traverse and emits deferred diagnostics based on the use graph implicitly generated during the traverse. Differential Revision: https://reviews.llvm.org/D70172
This commit is contained in:
parent
e8e078c8bf
commit
1b978ddba0
@ -1464,6 +1464,12 @@ public:
|
|||||||
|
|
||||||
void emitAndClearUnusedLocalTypedefWarnings();
|
void emitAndClearUnusedLocalTypedefWarnings();
|
||||||
|
|
||||||
|
// Emit all deferred diagnostics.
|
||||||
|
void emitDeferredDiags();
|
||||||
|
// Emit any deferred diagnostics for FD and erase them from the map in which
|
||||||
|
// they're stored.
|
||||||
|
void emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack);
|
||||||
|
|
||||||
enum TUFragmentKind {
|
enum TUFragmentKind {
|
||||||
/// The global module fragment, between 'module;' and a module-declaration.
|
/// The global module fragment, between 'module;' and a module-declaration.
|
||||||
Global,
|
Global,
|
||||||
@ -3683,7 +3689,8 @@ public:
|
|||||||
TemplateDiscarded, // Discarded due to uninstantiated templates
|
TemplateDiscarded, // Discarded due to uninstantiated templates
|
||||||
Unknown,
|
Unknown,
|
||||||
};
|
};
|
||||||
FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl);
|
FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl,
|
||||||
|
bool Final = false);
|
||||||
|
|
||||||
// Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check.
|
// Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check.
|
||||||
bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee);
|
bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee);
|
||||||
@ -9677,22 +9684,10 @@ private:
|
|||||||
/// Pop OpenMP function region for non-capturing function.
|
/// Pop OpenMP function region for non-capturing function.
|
||||||
void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
|
void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
|
||||||
|
|
||||||
/// Check whether we're allowed to call Callee from the current function.
|
|
||||||
void checkOpenMPDeviceFunction(SourceLocation Loc, FunctionDecl *Callee,
|
|
||||||
bool CheckForDelayedContext = true);
|
|
||||||
|
|
||||||
/// Check whether we're allowed to call Callee from the current function.
|
|
||||||
void checkOpenMPHostFunction(SourceLocation Loc, FunctionDecl *Callee,
|
|
||||||
bool CheckCaller = true);
|
|
||||||
|
|
||||||
/// Check if the expression is allowed to be used in expressions for the
|
/// Check if the expression is allowed to be used in expressions for the
|
||||||
/// OpenMP devices.
|
/// OpenMP devices.
|
||||||
void checkOpenMPDeviceExpr(const Expr *E);
|
void checkOpenMPDeviceExpr(const Expr *E);
|
||||||
|
|
||||||
/// Finishes analysis of the deferred functions calls that may be declared as
|
|
||||||
/// host/nohost during device/host compilation.
|
|
||||||
void finalizeOpenMPDelayedAnalysis();
|
|
||||||
|
|
||||||
/// Checks if a type or a declaration is disabled due to the owning extension
|
/// Checks if a type or a declaration is disabled due to the owning extension
|
||||||
/// being disabled, and emits diagnostic messages if it is disabled.
|
/// being disabled, and emits diagnostic messages if it is disabled.
|
||||||
/// \param D type or declaration to be checked.
|
/// \param D type or declaration to be checked.
|
||||||
@ -9875,6 +9870,11 @@ public:
|
|||||||
void
|
void
|
||||||
checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
|
checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
|
||||||
SourceLocation IdLoc = SourceLocation());
|
SourceLocation IdLoc = SourceLocation());
|
||||||
|
/// Finishes analysis of the deferred functions calls that may be declared as
|
||||||
|
/// host/nohost during device/host compilation.
|
||||||
|
void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
|
||||||
|
const FunctionDecl *Callee,
|
||||||
|
SourceLocation Loc);
|
||||||
/// Return true inside OpenMP declare target region.
|
/// Return true inside OpenMP declare target region.
|
||||||
bool isInOpenMPDeclareTargetContext() const {
|
bool isInOpenMPDeclareTargetContext() const {
|
||||||
return DeclareTargetNestingLevel > 0;
|
return DeclareTargetNestingLevel > 0;
|
||||||
@ -11223,18 +11223,6 @@ public:
|
|||||||
/* Caller = */ FunctionDeclAndLoc>
|
/* Caller = */ FunctionDeclAndLoc>
|
||||||
DeviceKnownEmittedFns;
|
DeviceKnownEmittedFns;
|
||||||
|
|
||||||
/// A partial call graph maintained during CUDA/OpenMP device code compilation
|
|
||||||
/// to support deferred diagnostics.
|
|
||||||
///
|
|
||||||
/// Functions are only added here if, at the time they're considered, they are
|
|
||||||
/// not known-emitted. As soon as we discover that a function is
|
|
||||||
/// known-emitted, we remove it and everything it transitively calls from this
|
|
||||||
/// set and add those functions to DeviceKnownEmittedFns.
|
|
||||||
llvm::DenseMap</* Caller = */ CanonicalDeclPtr<FunctionDecl>,
|
|
||||||
/* Callees = */ llvm::MapVector<CanonicalDeclPtr<FunctionDecl>,
|
|
||||||
SourceLocation>>
|
|
||||||
DeviceCallGraph;
|
|
||||||
|
|
||||||
/// Diagnostic builder for CUDA/OpenMP devices errors which may or may not be
|
/// Diagnostic builder for CUDA/OpenMP devices errors which may or may not be
|
||||||
/// deferred.
|
/// deferred.
|
||||||
///
|
///
|
||||||
@ -11309,14 +11297,6 @@ public:
|
|||||||
llvm::Optional<unsigned> PartialDiagId;
|
llvm::Optional<unsigned> PartialDiagId;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Indicate that this function (and thus everything it transtively calls)
|
|
||||||
/// will be codegen'ed, and emit any deferred diagnostics on this function and
|
|
||||||
/// its (transitive) callees.
|
|
||||||
void markKnownEmitted(
|
|
||||||
Sema &S, FunctionDecl *OrigCaller, FunctionDecl *OrigCallee,
|
|
||||||
SourceLocation OrigLoc,
|
|
||||||
const llvm::function_ref<bool(Sema &, FunctionDecl *)> IsKnownEmitted);
|
|
||||||
|
|
||||||
/// Creates a DeviceDiagBuilder that emits the diagnostic if the current context
|
/// Creates a DeviceDiagBuilder that emits the diagnostic if the current context
|
||||||
/// is "used as device code".
|
/// is "used as device code".
|
||||||
///
|
///
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "UsedDeclVisitor.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/ASTDiagnostic.h"
|
#include "clang/AST/ASTDiagnostic.h"
|
||||||
#include "clang/AST/DeclCXX.h"
|
#include "clang/AST/DeclCXX.h"
|
||||||
@ -954,9 +955,7 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
|
|||||||
PerformPendingInstantiations();
|
PerformPendingInstantiations();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finalize analysis of OpenMP-specific constructs.
|
emitDeferredDiags();
|
||||||
if (LangOpts.OpenMP)
|
|
||||||
finalizeOpenMPDelayedAnalysis();
|
|
||||||
|
|
||||||
assert(LateParsedInstantiations.empty() &&
|
assert(LateParsedInstantiations.empty() &&
|
||||||
"end of TU template instantiation should not create more "
|
"end of TU template instantiation should not create more "
|
||||||
@ -1451,27 +1450,128 @@ static void emitCallStackNotes(Sema &S, FunctionDecl *FD) {
|
|||||||
|
|
||||||
// Emit any deferred diagnostics for FD and erase them from the map in which
|
// Emit any deferred diagnostics for FD and erase them from the map in which
|
||||||
// they're stored.
|
// they're stored.
|
||||||
static void emitDeferredDiags(Sema &S, FunctionDecl *FD, bool ShowCallStack) {
|
void Sema::emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack) {
|
||||||
auto It = S.DeviceDeferredDiags.find(FD);
|
auto It = DeviceDeferredDiags.find(FD);
|
||||||
if (It == S.DeviceDeferredDiags.end())
|
if (It == DeviceDeferredDiags.end())
|
||||||
return;
|
return;
|
||||||
bool HasWarningOrError = false;
|
bool HasWarningOrError = false;
|
||||||
for (PartialDiagnosticAt &PDAt : It->second) {
|
for (PartialDiagnosticAt &PDAt : It->second) {
|
||||||
const SourceLocation &Loc = PDAt.first;
|
const SourceLocation &Loc = PDAt.first;
|
||||||
const PartialDiagnostic &PD = PDAt.second;
|
const PartialDiagnostic &PD = PDAt.second;
|
||||||
HasWarningOrError |= S.getDiagnostics().getDiagnosticLevel(
|
HasWarningOrError |= getDiagnostics().getDiagnosticLevel(
|
||||||
PD.getDiagID(), Loc) >= DiagnosticsEngine::Warning;
|
PD.getDiagID(), Loc) >= DiagnosticsEngine::Warning;
|
||||||
DiagnosticBuilder Builder(S.Diags.Report(Loc, PD.getDiagID()));
|
DiagnosticBuilder Builder(Diags.Report(Loc, PD.getDiagID()));
|
||||||
Builder.setForceEmit();
|
Builder.setForceEmit();
|
||||||
PD.Emit(Builder);
|
PD.Emit(Builder);
|
||||||
}
|
}
|
||||||
S.DeviceDeferredDiags.erase(It);
|
|
||||||
|
|
||||||
// FIXME: Should this be called after every warning/error emitted in the loop
|
// FIXME: Should this be called after every warning/error emitted in the loop
|
||||||
// above, instead of just once per function? That would be consistent with
|
// above, instead of just once per function? That would be consistent with
|
||||||
// how we handle immediate errors, but it also seems like a bit much.
|
// how we handle immediate errors, but it also seems like a bit much.
|
||||||
if (HasWarningOrError && ShowCallStack)
|
if (HasWarningOrError && ShowCallStack)
|
||||||
emitCallStackNotes(S, FD);
|
emitCallStackNotes(*this, FD);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/// Helper class that emits deferred diagnostic messages if an entity directly
|
||||||
|
/// or indirectly using the function that causes the deferred diagnostic
|
||||||
|
/// messages is known to be emitted.
|
||||||
|
class DeferredDiagnosticsEmitter
|
||||||
|
: public UsedDeclVisitor<DeferredDiagnosticsEmitter> {
|
||||||
|
public:
|
||||||
|
typedef UsedDeclVisitor<DeferredDiagnosticsEmitter> Inherited;
|
||||||
|
llvm::SmallSet<CanonicalDeclPtr<Decl>, 4> Visited;
|
||||||
|
llvm::SmallVector<CanonicalDeclPtr<FunctionDecl>, 4> UseStack;
|
||||||
|
bool ShouldEmit;
|
||||||
|
unsigned InOMPDeviceContext;
|
||||||
|
|
||||||
|
DeferredDiagnosticsEmitter(Sema &S)
|
||||||
|
: Inherited(S), ShouldEmit(false), InOMPDeviceContext(0) {}
|
||||||
|
|
||||||
|
void VisitDeclRefExpr(DeclRefExpr *E) {
|
||||||
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
|
||||||
|
visitUsedDecl(E->getLocation(), FD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisitMemberExpr(MemberExpr *E) {
|
||||||
|
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getMemberDecl()))
|
||||||
|
visitUsedDecl(E->getMemberLoc(), FD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisitOMPTargetDirective(OMPTargetDirective *Node) {
|
||||||
|
++InOMPDeviceContext;
|
||||||
|
Inherited::VisitOMPTargetDirective(Node);
|
||||||
|
--InOMPDeviceContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
void VisitCapturedStmt(CapturedStmt *Node) {
|
||||||
|
visitUsedDecl(Node->getBeginLoc(), Node->getCapturedDecl());
|
||||||
|
Inherited::VisitCapturedStmt(Node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void visitUsedDecl(SourceLocation Loc, Decl *D) {
|
||||||
|
if (auto *TD = dyn_cast<TranslationUnitDecl>(D)) {
|
||||||
|
for (auto *DD : TD->decls()) {
|
||||||
|
visitUsedDecl(Loc, DD);
|
||||||
|
}
|
||||||
|
} else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
|
||||||
|
for (auto *DD : FTD->specializations()) {
|
||||||
|
visitUsedDecl(Loc, DD);
|
||||||
|
}
|
||||||
|
} else if (auto *FD = dyn_cast<FunctionDecl>(D)) {
|
||||||
|
FunctionDecl *Caller = UseStack.empty() ? nullptr : UseStack.back();
|
||||||
|
auto IsKnownEmitted = S.getEmissionStatus(FD, /*Final=*/true) ==
|
||||||
|
Sema::FunctionEmissionStatus::Emitted;
|
||||||
|
if (!Caller)
|
||||||
|
ShouldEmit = IsKnownEmitted;
|
||||||
|
if ((!ShouldEmit && !S.getLangOpts().OpenMP && !Caller) ||
|
||||||
|
S.shouldIgnoreInHostDeviceCheck(FD) || Visited.count(D))
|
||||||
|
return;
|
||||||
|
// Finalize analysis of OpenMP-specific constructs.
|
||||||
|
if (Caller && S.LangOpts.OpenMP && UseStack.size() == 1)
|
||||||
|
S.finalizeOpenMPDelayedAnalysis(Caller, FD, Loc);
|
||||||
|
if (Caller)
|
||||||
|
S.DeviceKnownEmittedFns[FD] = {Caller, Loc};
|
||||||
|
if (ShouldEmit || InOMPDeviceContext)
|
||||||
|
S.emitDeferredDiags(FD, Caller);
|
||||||
|
Visited.insert(D);
|
||||||
|
UseStack.push_back(FD);
|
||||||
|
if (auto *S = FD->getBody()) {
|
||||||
|
this->Visit(S);
|
||||||
|
}
|
||||||
|
UseStack.pop_back();
|
||||||
|
Visited.erase(D);
|
||||||
|
} else if (auto *RD = dyn_cast<RecordDecl>(D)) {
|
||||||
|
for (auto *DD : RD->decls()) {
|
||||||
|
visitUsedDecl(Loc, DD);
|
||||||
|
}
|
||||||
|
} else if (auto *CD = dyn_cast<CapturedDecl>(D)) {
|
||||||
|
if (auto *S = CD->getBody()) {
|
||||||
|
this->Visit(S);
|
||||||
|
}
|
||||||
|
} else if (auto *VD = dyn_cast<VarDecl>(D)) {
|
||||||
|
if (auto *Init = VD->getInit()) {
|
||||||
|
auto DevTy = OMPDeclareTargetDeclAttr::getDeviceType(VD);
|
||||||
|
bool IsDev = DevTy && (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
|
||||||
|
*DevTy == OMPDeclareTargetDeclAttr::DT_Any);
|
||||||
|
if (IsDev)
|
||||||
|
++InOMPDeviceContext;
|
||||||
|
this->Visit(Init);
|
||||||
|
if (IsDev)
|
||||||
|
--InOMPDeviceContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void Sema::emitDeferredDiags() {
|
||||||
|
if (DeviceDeferredDiags.empty() && !LangOpts.OpenMP)
|
||||||
|
return;
|
||||||
|
|
||||||
|
DeferredDiagnosticsEmitter(*this).visitUsedDecl(
|
||||||
|
SourceLocation(), Context.getTranslationUnitDecl());
|
||||||
}
|
}
|
||||||
|
|
||||||
// In CUDA, there are some constructs which may appear in semantically-valid
|
// In CUDA, there are some constructs which may appear in semantically-valid
|
||||||
@ -1544,71 +1644,6 @@ Sema::DeviceDiagBuilder::~DeviceDiagBuilder() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Indicate that this function (and thus everything it transtively calls) will
|
|
||||||
// be codegen'ed, and emit any deferred diagnostics on this function and its
|
|
||||||
// (transitive) callees.
|
|
||||||
void Sema::markKnownEmitted(
|
|
||||||
Sema &S, FunctionDecl *OrigCaller, FunctionDecl *OrigCallee,
|
|
||||||
SourceLocation OrigLoc,
|
|
||||||
const llvm::function_ref<bool(Sema &, FunctionDecl *)> IsKnownEmitted) {
|
|
||||||
// Nothing to do if we already know that FD is emitted.
|
|
||||||
if (IsKnownEmitted(S, OrigCallee)) {
|
|
||||||
assert(!S.DeviceCallGraph.count(OrigCallee));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We've just discovered that OrigCallee is known-emitted. Walk our call
|
|
||||||
// graph to see what else we can now discover also must be emitted.
|
|
||||||
|
|
||||||
struct CallInfo {
|
|
||||||
FunctionDecl *Caller;
|
|
||||||
FunctionDecl *Callee;
|
|
||||||
SourceLocation Loc;
|
|
||||||
};
|
|
||||||
llvm::SmallVector<CallInfo, 4> Worklist = {{OrigCaller, OrigCallee, OrigLoc}};
|
|
||||||
llvm::SmallSet<CanonicalDeclPtr<FunctionDecl>, 4> Seen;
|
|
||||||
Seen.insert(OrigCallee);
|
|
||||||
while (!Worklist.empty()) {
|
|
||||||
CallInfo C = Worklist.pop_back_val();
|
|
||||||
assert(!IsKnownEmitted(S, C.Callee) &&
|
|
||||||
"Worklist should not contain known-emitted functions.");
|
|
||||||
S.DeviceKnownEmittedFns[C.Callee] = {C.Caller, C.Loc};
|
|
||||||
emitDeferredDiags(S, C.Callee, C.Caller);
|
|
||||||
|
|
||||||
// If this is a template instantiation, explore its callgraph as well:
|
|
||||||
// Non-dependent calls are part of the template's callgraph, while dependent
|
|
||||||
// calls are part of to the instantiation's call graph.
|
|
||||||
if (auto *Templ = C.Callee->getPrimaryTemplate()) {
|
|
||||||
FunctionDecl *TemplFD = Templ->getAsFunction();
|
|
||||||
if (!Seen.count(TemplFD) && !S.DeviceKnownEmittedFns.count(TemplFD)) {
|
|
||||||
Seen.insert(TemplFD);
|
|
||||||
Worklist.push_back(
|
|
||||||
{/* Caller = */ C.Caller, /* Callee = */ TemplFD, C.Loc});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add all functions called by Callee to our worklist.
|
|
||||||
auto CGIt = S.DeviceCallGraph.find(C.Callee);
|
|
||||||
if (CGIt == S.DeviceCallGraph.end())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (std::pair<CanonicalDeclPtr<FunctionDecl>, SourceLocation> FDLoc :
|
|
||||||
CGIt->second) {
|
|
||||||
FunctionDecl *NewCallee = FDLoc.first;
|
|
||||||
SourceLocation CallLoc = FDLoc.second;
|
|
||||||
if (Seen.count(NewCallee) || IsKnownEmitted(S, NewCallee))
|
|
||||||
continue;
|
|
||||||
Seen.insert(NewCallee);
|
|
||||||
Worklist.push_back(
|
|
||||||
{/* Caller = */ C.Callee, /* Callee = */ NewCallee, CallLoc});
|
|
||||||
}
|
|
||||||
|
|
||||||
// C.Callee is now known-emitted, so we no longer need to maintain its list
|
|
||||||
// of callees in DeviceCallGraph.
|
|
||||||
S.DeviceCallGraph.erase(CGIt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Sema::DeviceDiagBuilder Sema::targetDiag(SourceLocation Loc, unsigned DiagID) {
|
Sema::DeviceDiagBuilder Sema::targetDiag(SourceLocation Loc, unsigned DiagID) {
|
||||||
if (LangOpts.OpenMP)
|
if (LangOpts.OpenMP)
|
||||||
return LangOpts.OpenMPIsDevice ? diagIfOpenMPDeviceCode(Loc, DiagID)
|
return LangOpts.OpenMPIsDevice ? diagIfOpenMPDeviceCode(Loc, DiagID)
|
||||||
|
@ -674,25 +674,6 @@ bool Sema::CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee) {
|
|||||||
// Otherwise, mark the call in our call graph so we can traverse it later.
|
// Otherwise, mark the call in our call graph so we can traverse it later.
|
||||||
bool CallerKnownEmitted =
|
bool CallerKnownEmitted =
|
||||||
getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted;
|
getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted;
|
||||||
if (CallerKnownEmitted) {
|
|
||||||
// Host-side references to a __global__ function refer to the stub, so the
|
|
||||||
// function itself is never emitted and therefore should not be marked.
|
|
||||||
if (!shouldIgnoreInHostDeviceCheck(Callee))
|
|
||||||
markKnownEmitted(
|
|
||||||
*this, Caller, Callee, Loc, [](Sema &S, FunctionDecl *FD) {
|
|
||||||
return S.getEmissionStatus(FD) == FunctionEmissionStatus::Emitted;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// If we have
|
|
||||||
// host fn calls kernel fn calls host+device,
|
|
||||||
// the HD function does not get instantiated on the host. We model this by
|
|
||||||
// omitting at the call to the kernel from the callgraph. This ensures
|
|
||||||
// that, when compiling for host, only HD functions actually called from the
|
|
||||||
// host get marked as known-emitted.
|
|
||||||
if (!shouldIgnoreInHostDeviceCheck(Callee))
|
|
||||||
DeviceCallGraph[Caller].insert({Callee, Loc});
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceDiagBuilder::Kind DiagKind = [this, Caller, Callee,
|
DeviceDiagBuilder::Kind DiagKind = [this, Caller, Callee,
|
||||||
CallerKnownEmitted] {
|
CallerKnownEmitted] {
|
||||||
switch (IdentifyCUDAPreference(Caller, Callee)) {
|
switch (IdentifyCUDAPreference(Caller, Callee)) {
|
||||||
|
@ -17929,7 +17929,8 @@ Decl *Sema::getObjCDeclContext() const {
|
|||||||
return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
|
return (dyn_cast_or_null<ObjCContainerDecl>(CurContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
|
Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD,
|
||||||
|
bool Final) {
|
||||||
// Templates are emitted when they're instantiated.
|
// Templates are emitted when they're instantiated.
|
||||||
if (FD->isDependentContext())
|
if (FD->isDependentContext())
|
||||||
return FunctionEmissionStatus::TemplateDiscarded;
|
return FunctionEmissionStatus::TemplateDiscarded;
|
||||||
@ -17941,8 +17942,10 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
|
|||||||
if (DevTy.hasValue()) {
|
if (DevTy.hasValue()) {
|
||||||
if (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
|
if (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
|
||||||
OMPES = FunctionEmissionStatus::OMPDiscarded;
|
OMPES = FunctionEmissionStatus::OMPDiscarded;
|
||||||
else if (DeviceKnownEmittedFns.count(FD) > 0)
|
else if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost ||
|
||||||
|
*DevTy == OMPDeclareTargetDeclAttr::DT_Any) {
|
||||||
OMPES = FunctionEmissionStatus::Emitted;
|
OMPES = FunctionEmissionStatus::Emitted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (LangOpts.OpenMP) {
|
} else if (LangOpts.OpenMP) {
|
||||||
// In OpenMP 4.5 all the functions are host functions.
|
// In OpenMP 4.5 all the functions are host functions.
|
||||||
@ -17958,10 +17961,11 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
|
|||||||
if (DevTy.hasValue()) {
|
if (DevTy.hasValue()) {
|
||||||
if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) {
|
if (*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) {
|
||||||
OMPES = FunctionEmissionStatus::OMPDiscarded;
|
OMPES = FunctionEmissionStatus::OMPDiscarded;
|
||||||
} else if (DeviceKnownEmittedFns.count(FD) > 0) {
|
} else if (*DevTy == OMPDeclareTargetDeclAttr::DT_Host ||
|
||||||
|
*DevTy == OMPDeclareTargetDeclAttr::DT_Any)
|
||||||
OMPES = FunctionEmissionStatus::Emitted;
|
OMPES = FunctionEmissionStatus::Emitted;
|
||||||
}
|
} else if (Final)
|
||||||
}
|
OMPES = FunctionEmissionStatus::Emitted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OMPES == FunctionEmissionStatus::OMPDiscarded ||
|
if (OMPES == FunctionEmissionStatus::OMPDiscarded ||
|
||||||
@ -17996,9 +18000,7 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(FunctionDecl *FD) {
|
|||||||
|
|
||||||
// Otherwise, the function is known-emitted if it's in our set of
|
// Otherwise, the function is known-emitted if it's in our set of
|
||||||
// known-emitted functions.
|
// known-emitted functions.
|
||||||
return (DeviceKnownEmittedFns.count(FD) > 0)
|
return FunctionEmissionStatus::Unknown;
|
||||||
? FunctionEmissionStatus::Emitted
|
|
||||||
: FunctionEmissionStatus::Unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Sema::shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee) {
|
bool Sema::shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee) {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "TreeTransform.h"
|
#include "TreeTransform.h"
|
||||||
|
#include "UsedDeclVisitor.h"
|
||||||
#include "clang/AST/ASTConsumer.h"
|
#include "clang/AST/ASTConsumer.h"
|
||||||
#include "clang/AST/ASTContext.h"
|
#include "clang/AST/ASTContext.h"
|
||||||
#include "clang/AST/ASTLambda.h"
|
#include "clang/AST/ASTLambda.h"
|
||||||
@ -15898,13 +15899,8 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
|
|||||||
Func->markUsed(Context);
|
Func->markUsed(Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LangOpts.OpenMP) {
|
if (LangOpts.OpenMP)
|
||||||
markOpenMPDeclareVariantFuncsReferenced(Loc, Func, MightBeOdrUse);
|
markOpenMPDeclareVariantFuncsReferenced(Loc, Func, MightBeOdrUse);
|
||||||
if (LangOpts.OpenMPIsDevice)
|
|
||||||
checkOpenMPDeviceFunction(Loc, Func);
|
|
||||||
else
|
|
||||||
checkOpenMPHostFunction(Loc, Func);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Directly mark a variable odr-used. Given a choice, prefer to use
|
/// Directly mark a variable odr-used. Given a choice, prefer to use
|
||||||
@ -17296,71 +17292,33 @@ void Sema::MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/// Helper class that marks all of the declarations referenced by
|
/// Helper class that marks all of the declarations referenced by
|
||||||
/// potentially-evaluated subexpressions as "referenced".
|
/// potentially-evaluated subexpressions as "referenced".
|
||||||
class EvaluatedExprMarker : public EvaluatedExprVisitor<EvaluatedExprMarker> {
|
class EvaluatedExprMarker : public UsedDeclVisitor<EvaluatedExprMarker> {
|
||||||
Sema &S;
|
public:
|
||||||
bool SkipLocalVariables;
|
typedef UsedDeclVisitor<EvaluatedExprMarker> Inherited;
|
||||||
|
bool SkipLocalVariables;
|
||||||
|
|
||||||
public:
|
EvaluatedExprMarker(Sema &S, bool SkipLocalVariables)
|
||||||
typedef EvaluatedExprVisitor<EvaluatedExprMarker> Inherited;
|
: Inherited(S), SkipLocalVariables(SkipLocalVariables) {}
|
||||||
|
|
||||||
EvaluatedExprMarker(Sema &S, bool SkipLocalVariables)
|
void visitUsedDecl(SourceLocation Loc, Decl *D) {
|
||||||
: Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { }
|
S.MarkFunctionReferenced(Loc, cast<FunctionDecl>(D));
|
||||||
|
}
|
||||||
|
|
||||||
void VisitDeclRefExpr(DeclRefExpr *E) {
|
void VisitDeclRefExpr(DeclRefExpr *E) {
|
||||||
// If we were asked not to visit local variables, don't.
|
// If we were asked not to visit local variables, don't.
|
||||||
if (SkipLocalVariables) {
|
if (SkipLocalVariables) {
|
||||||
if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()))
|
if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()))
|
||||||
if (VD->hasLocalStorage())
|
if (VD->hasLocalStorage())
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
S.MarkDeclRefReferenced(E);
|
|
||||||
}
|
}
|
||||||
|
S.MarkDeclRefReferenced(E);
|
||||||
|
}
|
||||||
|
|
||||||
void VisitMemberExpr(MemberExpr *E) {
|
void VisitMemberExpr(MemberExpr *E) { S.MarkMemberReferenced(E); }
|
||||||
S.MarkMemberReferenced(E);
|
};
|
||||||
Inherited::VisitMemberExpr(E);
|
} // namespace
|
||||||
}
|
|
||||||
|
|
||||||
void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
|
|
||||||
S.MarkFunctionReferenced(
|
|
||||||
E->getBeginLoc(),
|
|
||||||
const_cast<CXXDestructorDecl *>(E->getTemporary()->getDestructor()));
|
|
||||||
Visit(E->getSubExpr());
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisitCXXNewExpr(CXXNewExpr *E) {
|
|
||||||
if (E->getOperatorNew())
|
|
||||||
S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorNew());
|
|
||||||
if (E->getOperatorDelete())
|
|
||||||
S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete());
|
|
||||||
Inherited::VisitCXXNewExpr(E);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
|
|
||||||
if (E->getOperatorDelete())
|
|
||||||
S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete());
|
|
||||||
QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
|
|
||||||
if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
|
|
||||||
CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
|
|
||||||
S.MarkFunctionReferenced(E->getBeginLoc(), S.LookupDestructor(Record));
|
|
||||||
}
|
|
||||||
|
|
||||||
Inherited::VisitCXXDeleteExpr(E);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisitCXXConstructExpr(CXXConstructExpr *E) {
|
|
||||||
S.MarkFunctionReferenced(E->getBeginLoc(), E->getConstructor());
|
|
||||||
Inherited::VisitCXXConstructExpr(E);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
|
|
||||||
Visit(E->getExpr());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mark any declarations that appear within this expression or any
|
/// Mark any declarations that appear within this expression or any
|
||||||
/// potentially-evaluated subexpressions as "referenced".
|
/// potentially-evaluated subexpressions as "referenced".
|
||||||
|
@ -1710,92 +1710,6 @@ Sema::DeviceDiagBuilder Sema::diagIfOpenMPHostCode(SourceLocation Loc,
|
|||||||
return DeviceDiagBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this);
|
return DeviceDiagBuilder(Kind, Loc, DiagID, getCurFunctionDecl(), *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::checkOpenMPDeviceFunction(SourceLocation Loc, FunctionDecl *Callee,
|
|
||||||
bool CheckForDelayedContext) {
|
|
||||||
assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice &&
|
|
||||||
"Expected OpenMP device compilation.");
|
|
||||||
assert(Callee && "Callee may not be null.");
|
|
||||||
Callee = Callee->getMostRecentDecl();
|
|
||||||
FunctionDecl *Caller = getCurFunctionDecl();
|
|
||||||
|
|
||||||
// host only function are not available on the device.
|
|
||||||
if (Caller) {
|
|
||||||
FunctionEmissionStatus CallerS = getEmissionStatus(Caller);
|
|
||||||
FunctionEmissionStatus CalleeS = getEmissionStatus(Callee);
|
|
||||||
assert(CallerS != FunctionEmissionStatus::CUDADiscarded &&
|
|
||||||
CalleeS != FunctionEmissionStatus::CUDADiscarded &&
|
|
||||||
"CUDADiscarded unexpected in OpenMP device function check");
|
|
||||||
if ((CallerS == FunctionEmissionStatus::Emitted ||
|
|
||||||
(!isOpenMPDeviceDelayedContext(*this) &&
|
|
||||||
CallerS == FunctionEmissionStatus::Unknown)) &&
|
|
||||||
CalleeS == FunctionEmissionStatus::OMPDiscarded) {
|
|
||||||
StringRef HostDevTy = getOpenMPSimpleClauseTypeName(
|
|
||||||
OMPC_device_type, OMPC_DEVICE_TYPE_host);
|
|
||||||
Diag(Loc, diag::err_omp_wrong_device_function_call) << HostDevTy << 0;
|
|
||||||
Diag(Callee->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(),
|
|
||||||
diag::note_omp_marked_device_type_here)
|
|
||||||
<< HostDevTy;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If the caller is known-emitted, mark the callee as known-emitted.
|
|
||||||
// Otherwise, mark the call in our call graph so we can traverse it later.
|
|
||||||
if ((CheckForDelayedContext && !isOpenMPDeviceDelayedContext(*this)) ||
|
|
||||||
(!Caller && !CheckForDelayedContext) ||
|
|
||||||
(Caller && getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted))
|
|
||||||
markKnownEmitted(*this, Caller, Callee, Loc,
|
|
||||||
[CheckForDelayedContext](Sema &S, FunctionDecl *FD) {
|
|
||||||
return CheckForDelayedContext &&
|
|
||||||
S.getEmissionStatus(FD) ==
|
|
||||||
FunctionEmissionStatus::Emitted;
|
|
||||||
});
|
|
||||||
else if (Caller)
|
|
||||||
DeviceCallGraph[Caller].insert({Callee, Loc});
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sema::checkOpenMPHostFunction(SourceLocation Loc, FunctionDecl *Callee,
|
|
||||||
bool CheckCaller) {
|
|
||||||
assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice &&
|
|
||||||
"Expected OpenMP host compilation.");
|
|
||||||
assert(Callee && "Callee may not be null.");
|
|
||||||
Callee = Callee->getMostRecentDecl();
|
|
||||||
FunctionDecl *Caller = getCurFunctionDecl();
|
|
||||||
|
|
||||||
// device only function are not available on the host.
|
|
||||||
if (Caller) {
|
|
||||||
FunctionEmissionStatus CallerS = getEmissionStatus(Caller);
|
|
||||||
FunctionEmissionStatus CalleeS = getEmissionStatus(Callee);
|
|
||||||
assert(
|
|
||||||
(LangOpts.CUDA || (CallerS != FunctionEmissionStatus::CUDADiscarded &&
|
|
||||||
CalleeS != FunctionEmissionStatus::CUDADiscarded)) &&
|
|
||||||
"CUDADiscarded unexpected in OpenMP host function check");
|
|
||||||
if (CallerS == FunctionEmissionStatus::Emitted &&
|
|
||||||
CalleeS == FunctionEmissionStatus::OMPDiscarded) {
|
|
||||||
StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName(
|
|
||||||
OMPC_device_type, OMPC_DEVICE_TYPE_nohost);
|
|
||||||
Diag(Loc, diag::err_omp_wrong_device_function_call) << NoHostDevTy << 1;
|
|
||||||
Diag(Callee->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(),
|
|
||||||
diag::note_omp_marked_device_type_here)
|
|
||||||
<< NoHostDevTy;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If the caller is known-emitted, mark the callee as known-emitted.
|
|
||||||
// Otherwise, mark the call in our call graph so we can traverse it later.
|
|
||||||
if (!shouldIgnoreInHostDeviceCheck(Callee)) {
|
|
||||||
if ((!CheckCaller && !Caller) ||
|
|
||||||
(Caller &&
|
|
||||||
getEmissionStatus(Caller) == FunctionEmissionStatus::Emitted))
|
|
||||||
markKnownEmitted(
|
|
||||||
*this, Caller, Callee, Loc, [CheckCaller](Sema &S, FunctionDecl *FD) {
|
|
||||||
return CheckCaller &&
|
|
||||||
S.getEmissionStatus(FD) == FunctionEmissionStatus::Emitted;
|
|
||||||
});
|
|
||||||
else if (Caller)
|
|
||||||
DeviceCallGraph[Caller].insert({Callee, Loc});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sema::checkOpenMPDeviceExpr(const Expr *E) {
|
void Sema::checkOpenMPDeviceExpr(const Expr *E) {
|
||||||
assert(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
|
assert(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice &&
|
||||||
"OpenMP device compilation mode is expected.");
|
"OpenMP device compilation mode is expected.");
|
||||||
@ -2208,52 +2122,43 @@ bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level,
|
|||||||
|
|
||||||
void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; }
|
void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; }
|
||||||
|
|
||||||
void Sema::finalizeOpenMPDelayedAnalysis() {
|
void Sema::finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
|
||||||
|
const FunctionDecl *Callee,
|
||||||
|
SourceLocation Loc) {
|
||||||
assert(LangOpts.OpenMP && "Expected OpenMP compilation mode.");
|
assert(LangOpts.OpenMP && "Expected OpenMP compilation mode.");
|
||||||
// Diagnose implicit declare target functions and their callees.
|
Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
|
||||||
for (const auto &CallerCallees : DeviceCallGraph) {
|
OMPDeclareTargetDeclAttr::getDeviceType(Caller->getMostRecentDecl());
|
||||||
Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
|
// Ignore host functions during device analyzis.
|
||||||
OMPDeclareTargetDeclAttr::getDeviceType(
|
if (LangOpts.OpenMPIsDevice && DevTy &&
|
||||||
CallerCallees.getFirst()->getMostRecentDecl());
|
*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
|
||||||
// Ignore host functions during device analyzis.
|
return;
|
||||||
if (LangOpts.OpenMPIsDevice && DevTy &&
|
// Ignore nohost functions during host analyzis.
|
||||||
*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
|
if (!LangOpts.OpenMPIsDevice && DevTy &&
|
||||||
continue;
|
*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
|
||||||
// Ignore nohost functions during host analyzis.
|
return;
|
||||||
if (!LangOpts.OpenMPIsDevice && DevTy &&
|
const FunctionDecl *FD = Callee->getMostRecentDecl();
|
||||||
*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost)
|
DevTy = OMPDeclareTargetDeclAttr::getDeviceType(FD);
|
||||||
continue;
|
if (LangOpts.OpenMPIsDevice && DevTy &&
|
||||||
for (const std::pair<CanonicalDeclPtr<FunctionDecl>, SourceLocation>
|
*DevTy == OMPDeclareTargetDeclAttr::DT_Host) {
|
||||||
&Callee : CallerCallees.getSecond()) {
|
// Diagnose host function called during device codegen.
|
||||||
const FunctionDecl *FD = Callee.first->getMostRecentDecl();
|
StringRef HostDevTy =
|
||||||
Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
|
getOpenMPSimpleClauseTypeName(OMPC_device_type, OMPC_DEVICE_TYPE_host);
|
||||||
OMPDeclareTargetDeclAttr::getDeviceType(FD);
|
Diag(Loc, diag::err_omp_wrong_device_function_call) << HostDevTy << 0;
|
||||||
if (LangOpts.OpenMPIsDevice && DevTy &&
|
Diag(FD->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(),
|
||||||
*DevTy == OMPDeclareTargetDeclAttr::DT_Host) {
|
diag::note_omp_marked_device_type_here)
|
||||||
// Diagnose host function called during device codegen.
|
<< HostDevTy;
|
||||||
StringRef HostDevTy = getOpenMPSimpleClauseTypeName(
|
return;
|
||||||
OMPC_device_type, OMPC_DEVICE_TYPE_host);
|
}
|
||||||
Diag(Callee.second, diag::err_omp_wrong_device_function_call)
|
|
||||||
<< HostDevTy << 0;
|
|
||||||
Diag(FD->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(),
|
|
||||||
diag::note_omp_marked_device_type_here)
|
|
||||||
<< HostDevTy;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!LangOpts.OpenMPIsDevice && DevTy &&
|
if (!LangOpts.OpenMPIsDevice && DevTy &&
|
||||||
*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) {
|
*DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) {
|
||||||
// Diagnose nohost function called during host codegen.
|
// Diagnose nohost function called during host codegen.
|
||||||
StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName(
|
StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName(
|
||||||
OMPC_device_type, OMPC_DEVICE_TYPE_nohost);
|
OMPC_device_type, OMPC_DEVICE_TYPE_nohost);
|
||||||
Diag(Callee.second, diag::err_omp_wrong_device_function_call)
|
Diag(Loc, diag::err_omp_wrong_device_function_call) << NoHostDevTy << 1;
|
||||||
<< NoHostDevTy << 1;
|
|
||||||
Diag(FD->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(),
|
Diag(FD->getAttr<OMPDeclareTargetDeclAttr>()->getLocation(),
|
||||||
diag::note_omp_marked_device_type_here)
|
diag::note_omp_marked_device_type_here)
|
||||||
<< NoHostDevTy;
|
<< NoHostDevTy;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind,
|
void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind,
|
||||||
@ -17172,15 +17077,6 @@ void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
|
|||||||
Diag(FD->getLocation(), diag::note_defined_here) << FD;
|
Diag(FD->getLocation(), diag::note_defined_here) << FD;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Mark the function as must be emitted for the device.
|
|
||||||
Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy =
|
|
||||||
OMPDeclareTargetDeclAttr::getDeviceType(FD);
|
|
||||||
if (LangOpts.OpenMPIsDevice && Res.hasValue() && IdLoc.isValid() &&
|
|
||||||
*DevTy != OMPDeclareTargetDeclAttr::DT_Host)
|
|
||||||
checkOpenMPDeviceFunction(IdLoc, FD, /*CheckForDelayedContext=*/false);
|
|
||||||
if (!LangOpts.OpenMPIsDevice && Res.hasValue() && IdLoc.isValid() &&
|
|
||||||
*DevTy != OMPDeclareTargetDeclAttr::DT_NoHost)
|
|
||||||
checkOpenMPHostFunction(IdLoc, FD, /*CheckCaller=*/false);
|
|
||||||
}
|
}
|
||||||
if (auto *VD = dyn_cast<ValueDecl>(D)) {
|
if (auto *VD = dyn_cast<ValueDecl>(D)) {
|
||||||
// Problem if any with var declared with incomplete type will be reported
|
// Problem if any with var declared with incomplete type will be reported
|
||||||
|
@ -162,17 +162,17 @@ namespace {
|
|||||||
#pragma omp declare target link(x) // expected-error {{'x' must not appear in both clauses 'to' and 'link'}}
|
#pragma omp declare target link(x) // expected-error {{'x' must not appear in both clauses 'to' and 'link'}}
|
||||||
|
|
||||||
void bazz() {}
|
void bazz() {}
|
||||||
#pragma omp declare target to(bazz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} host5-note {{marked as 'device_type(nohost)' here}}
|
#pragma omp declare target to(bazz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} host5-note 3{{marked as 'device_type(nohost)' here}}
|
||||||
void bazzz() {bazz();}
|
void bazzz() {bazz();}
|
||||||
#pragma omp declare target to(bazzz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}}
|
#pragma omp declare target to(bazzz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}}
|
||||||
void any() {bazz();} // host5-error {{function with 'device_type(nohost)' is not available on host}}
|
void any() {bazz();} // host5-error {{function with 'device_type(nohost)' is not available on host}}
|
||||||
void host1() {bazz();}
|
void host1() {bazz();} // host5-error {{function with 'device_type(nohost)' is not available on host}}
|
||||||
#pragma omp declare target to(host1) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} dev5-note 2 {{marked as 'device_type(host)' here}}
|
#pragma omp declare target to(host1) device_type(host) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} dev5-note 4 {{marked as 'device_type(host)' here}}
|
||||||
void host2() {bazz();}
|
void host2() {bazz();} //host5-error {{function with 'device_type(nohost)' is not available on host}}
|
||||||
#pragma omp declare target to(host2)
|
#pragma omp declare target to(host2)
|
||||||
void device() {host1();}
|
void device() {host1();} // dev5-error {{function with 'device_type(host)' is not available on device}}
|
||||||
#pragma omp declare target to(device) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} host5-note 2 {{marked as 'device_type(nohost)' here}}
|
#pragma omp declare target to(device) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}} host5-note 2 {{marked as 'device_type(nohost)' here}}
|
||||||
void host3() {host1();}
|
void host3() {host1();} // dev5-error {{function with 'device_type(host)' is not available on device}}
|
||||||
#pragma omp declare target to(host3)
|
#pragma omp declare target to(host3)
|
||||||
|
|
||||||
#pragma omp declare target
|
#pragma omp declare target
|
||||||
|
@ -38,7 +38,7 @@ int d;
|
|||||||
#pragma omp end declare target
|
#pragma omp end declare target
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
int bar() { return 1 + foo() + bar() + baz1() + baz2(); }
|
int bar() { return 1 + foo() + bar() + baz1() + baz2(); } // expected-note {{called by 'bar'}}
|
||||||
|
|
||||||
int maini1() {
|
int maini1() {
|
||||||
int a;
|
int a;
|
||||||
@ -49,7 +49,7 @@ int maini1() {
|
|||||||
{
|
{
|
||||||
S s(a);
|
S s(a);
|
||||||
static long aaa = 23;
|
static long aaa = 23;
|
||||||
a = foo() + bar() + b + c + d + aa + aaa + FA<int>();
|
a = foo() + bar() + b + c + d + aa + aaa + FA<int>(); // expected-note{{called by 'maini1'}}
|
||||||
if (!a)
|
if (!a)
|
||||||
throw "Error"; // expected-error {{cannot use 'throw' with exceptions disabled}}
|
throw "Error"; // expected-error {{cannot use 'throw' with exceptions disabled}}
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ inline __host__ __device__ void hd() {
|
|||||||
|
|
||||||
void host_fn() {
|
void host_fn() {
|
||||||
hd<int>();
|
hd<int>();
|
||||||
hd<double>(); // expected-note {{function template specialization 'hd<double>'}}
|
hd<double>();
|
||||||
// expected-note@-1 {{called by 'host_fn'}}
|
// expected-note@-1 {{called by 'host_fn'}}
|
||||||
hd<float>(); // expected-note {{function template specialization 'hd<float>'}}
|
hd<float>();
|
||||||
// expected-note@-1 {{called by 'host_fn'}}
|
// expected-note@-1 {{called by 'host_fn'}}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
|
// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
|
||||||
// RUN: -verify -verify-ignore-unexpected=note
|
// RUN: -verify -verify-ignore-unexpected=note
|
||||||
// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
|
// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
|
||||||
// RUN: -verify -verify-ignore-unexpected=note -fopenmp
|
// RUN: -verify=expected,omp -verify-ignore-unexpected=note -fopenmp
|
||||||
|
|
||||||
// Note: This test won't work with -fsyntax-only, because some of these errors
|
// Note: This test won't work with -fsyntax-only, because some of these errors
|
||||||
// are emitted during codegen.
|
// are emitted during codegen.
|
||||||
@ -39,7 +39,7 @@ __host__ __device__ void T::hd3() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> __host__ __device__ void hd2() { device_fn(); }
|
template <typename T> __host__ __device__ void hd2() { device_fn(); }
|
||||||
// expected-error@-1 2 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
|
// expected-error@-1 {{reference to __device__ function 'device_fn' in __host__ __device__ function}}
|
||||||
void host_fn() { hd2<int>(); }
|
void host_fn() { hd2<int>(); }
|
||||||
|
|
||||||
__host__ __device__ void hd() { device_fn(); }
|
__host__ __device__ void hd() { device_fn(); }
|
||||||
|
@ -56,14 +56,14 @@ __host__ __device__ void T::hd3() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> __host__ __device__ void hd2() { host_fn(); }
|
template <typename T> __host__ __device__ void hd2() { host_fn(); }
|
||||||
// expected-error@-1 2 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
|
// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
|
||||||
__global__ void kernel() { hd2<int>(); }
|
__global__ void kernel() { hd2<int>(); }
|
||||||
|
|
||||||
__host__ __device__ void hd() { host_fn(); }
|
__host__ __device__ void hd() { host_fn(); }
|
||||||
// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
|
// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
|
||||||
|
|
||||||
template <typename T> __host__ __device__ void hd3() { host_fn(); }
|
template <typename T> __host__ __device__ void hd3() { host_fn(); }
|
||||||
// expected-error@-1 2 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
|
// expected-error@-1 {{reference to __host__ function 'host_fn' in __host__ __device__ function}}
|
||||||
__device__ void device_fn() { hd3<int>(); }
|
__device__ void device_fn() { hd3<int>(); }
|
||||||
|
|
||||||
// No error because this is never instantiated.
|
// No error because this is never instantiated.
|
||||||
|
@ -16,9 +16,9 @@ void bazz() {}
|
|||||||
void bazzz() {bazz();}
|
void bazzz() {bazz();}
|
||||||
#pragma omp declare target to(bazzz) device_type(nohost)
|
#pragma omp declare target to(bazzz) device_type(nohost)
|
||||||
void any() {bazz();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
|
void any() {bazz();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
|
||||||
void host1() {bazz();}
|
void host1() {bazz();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
|
||||||
#pragma omp declare target to(host1) device_type(host)
|
#pragma omp declare target to(host1) device_type(host)
|
||||||
void host2() {bazz();}
|
void host2() {bazz();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
|
||||||
#pragma omp declare target to(host2)
|
#pragma omp declare target to(host2)
|
||||||
void device() {host1();}
|
void device() {host1();}
|
||||||
#pragma omp declare target to(device) device_type(nohost)
|
#pragma omp declare target to(device) device_type(nohost)
|
||||||
|
@ -38,7 +38,7 @@ void launch_kernel() {
|
|||||||
// Notice that these two diagnostics are different: Because the call to hd1
|
// Notice that these two diagnostics are different: Because the call to hd1
|
||||||
// is not dependent on T, the call to hd1 comes from 'launch_kernel', while
|
// is not dependent on T, the call to hd1 comes from 'launch_kernel', while
|
||||||
// the call to hd3, being dependent, comes from 'launch_kernel<int>'.
|
// the call to hd3, being dependent, comes from 'launch_kernel<int>'.
|
||||||
hd1(); // expected-note {{called by 'launch_kernel'}}
|
hd1(); // expected-note {{called by 'launch_kernel<int>'}}
|
||||||
hd3(T()); // expected-note {{called by 'launch_kernel<int>'}}
|
hd3(T()); // expected-note {{called by 'launch_kernel<int>'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user