Skip to content
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
10 changes: 10 additions & 0 deletions clang/lib/DPCT/RuleInfra/ExprAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ bool isCGAPI(std::string Name) {
return MapNamesLang::CooperativeGroupsAPISet.count(Name);
}

void ExprAnalysis::analyzeExpr(const DependentScopeDeclRefExpr *DRE) {
std::string Result;
llvm::raw_string_ostream OS(Result);
DRE->getQualifier()->dump(OS);
std::string cuda_std_prefix = "cuda::std::";
if (Result.find(cuda_std_prefix) == 0) {
addReplacement(DRE->getBeginLoc(), cuda_std_prefix.length(), "std::");
}
}

void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
std::string CTSName;
auto Qualifier = DRE->getQualifier();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/RuleInfra/ExprAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ class ExprAnalysis {
}

inline void analyzeExpr(const DeclRefExpr *DRE);

inline void analyzeExpr(const DependentScopeDeclRefExpr *DRE);
inline void analyzeExpr(const ParenExpr *PE) { dispatch(PE->getSubExpr()); }

inline void analyzeExpr(const ArraySubscriptExpr *ASE) {
Expand Down
11 changes: 10 additions & 1 deletion clang/lib/DPCT/RulesLangLib/LIBCUAPIMigration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ void LIBCURule::registerMatcher(ast_matchers::MatchFinder &MF) {
.bind("MemberCall"),
this);
}

{
MF.addMatcher(dependentScopeDeclRefExpr().bind("DependentScope"),
this);
}
{
auto LIBCUTypesNames = [&]() {
return hasAnyName("atomic", "cuda::std::complex", "cuda::std::array",
Expand Down Expand Up @@ -76,6 +79,12 @@ void LIBCURule::registerMatcher(ast_matchers::MatchFinder &MF) {

void LIBCURule::runRule(const ast_matchers::MatchFinder::MatchResult &Result) {
ExprAnalysis EA;
if (const auto *DSDRE =
getNodeAsType<DependentScopeDeclRefExpr>(Result, "DependentScope")) {
EA.analyze(DSDRE);
emplaceTransformation(EA.getReplacement());
EA.applyAllSubExprRepl();
}
if (const CXXMemberCallExpr *MC =
getNodeAsType<CXXMemberCallExpr>(Result, "MemberCall")) {
EA.analyze(MC);
Expand Down
26 changes: 26 additions & 0 deletions clang/test/dpct/LibCU/libcu_num.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// UNSUPPORTED: v7.0, v7.5, v8.0, v9.0, v9.2, v10.0
// UNSUPPORTED: cuda-7.0, cuda-7.5, cuda-8.0, cuda-9.0, cuda-9.2, cuda-10.0
// RUN: dpct --format-range=none -in-root %S -out-root %T/Libcu %S/libcu_num.cu --cuda-include-path="%cuda-path/include" -- -std=c++14 -x cuda --cuda-host-only
// RUN: FileCheck --input-file %T/Libcu/libcu_num.dp.cpp --match-full-lines %s
// RUN: %if build_lit %{icpx -c -fsycl %T/Libcu/libcu_num.dp.cpp -o %T/Libcu/libcu_num.dp.o %}

#include <cuda/std/climits>
#include <cuda/std/type_traits>
#include <cuda/std/limits>
#include <cuda/std/tuple>

#include <iostream>
template <typename T> T init_value() {
//CHECK: return -std::numeric_limits<T>::infinity();
return -cuda::std::numeric_limits<T>::infinity();
}
//CHECK: template <typename T> constexpr T terminate_value() { return std::numeric_limits<T>::infinity(); }
template <typename T> constexpr T terminate_value() { return cuda::std::numeric_limits<T>::infinity(); }

template <class T> bool is_complete(const T &result) { return result != init_value<T>(); }


int main() {
std::cout << init_value<int>();
return 0;
}
Loading