@@ -41,6 +41,11 @@ extern DpctOption<opt, bool> ProcessAll;
4141extern DpctOption<opt, bool > AsyncHandler;
4242
4343namespace clang {
44+ namespace ast_matchers {
45+ AST_MATCHER (VarDecl, hasRegisterStorage) {
46+ return Node.getStorageClass () == SC_Register;
47+ }
48+ } // namespace ast_matchers
4449namespace dpct {
4550
4651void LinkageSpecDeclRule::registerMatcher (MatchFinder &MF ) {
@@ -1282,22 +1287,25 @@ void RemoveBaseClassRule::runRule(const MatchFinder::MatchResult &Result) {
12821287 }
12831288}
12841289
1285- // The EDG frontend can allow code like below:
1286- //
1287- // template <class T1, class T2> struct AAAAA {
1288- // template <class T3> void foo(T3 x);
1289- // };
1290- // template <typename T4, typename T5>
1291- // template <typename T6>
1292- // void AAAAA<T4, T5>::foo<T6>(T6 x) {}
1293- //
1294- // But clang/gcc emits error.
1295- // We suppress the error in Sema and record the source range and remove
1296- // the "invalid" code in this rule.
12971290void CompatWithClangRule::registerMatcher (ast_matchers::MatchFinder &MF ) {
1291+ // The EDG frontend can allow code like below:
1292+ //
1293+ // template <class T1, class T2> struct AAAAA {
1294+ // template <class T3> void foo(T3 x);
1295+ // };
1296+ // template <typename T4, typename T5>
1297+ // template <typename T6>
1298+ // void AAAAA<T4, T5>::foo<T6>(T6 x) {}
1299+ //
1300+ // But clang/gcc emits error.
1301+ // We suppress the error in Sema and record the source range and remove
1302+ // the "invalid" code in this rule.
12981303 MF .addMatcher (
12991304 cxxMethodDecl (hasParent (functionTemplateDecl ())).bind (" TemplateMethod" ),
13001305 this );
1306+ // ISO C++17 does not allow the 'register' storage class specifier. nvcc
1307+ // issues a warning when it encounters it, but keeps compiling.
1308+ MF .addMatcher (varDecl (hasRegisterStorage ()).bind (" RegisterStorage" ), this );
13011309}
13021310
13031311void CompatWithClangRule::runRule (
@@ -1314,6 +1322,12 @@ void CompatWithClangRule::runRule(
13141322 auto Length = End.getRawEncoding () - Begin.getRawEncoding ();
13151323 emplaceTransformation (new ReplaceText (Begin, Length, " " ));
13161324 }
1325+ } else if (const auto *VD =
1326+ getNodeAsType<VarDecl>(Result, " RegisterStorage" )) {
1327+ SourceLocation SL = VD ->getStorageClassSpecLoc ();
1328+ if (DpctGlobalInfo::getContext ().getLangOpts ().CUDA && SL .isValid ()) {
1329+ emplaceTransformation (new ReplaceText (SL , std::strlen (" register" ), " " ));
1330+ }
13171331 }
13181332}
13191333
0 commit comments