@@ -1375,7 +1375,7 @@ auto FunctionBuilderBuilder::build(const clang::FunctionDecl *S, bool allowKerne
1375
1375
}
1376
1376
1377
1377
// collect args
1378
- for ( auto param : params) {
1378
+ auto collect_arg = [&] ( const VarDecl* param) -> const luisa::compute::RefExpr* {
1379
1379
auto Ty = param->getType ();
1380
1380
if (auto lcType = db->FindOrAddType (Ty, param->getBeginLoc ())) {
1381
1381
const luisa::compute::RefExpr *local = nullptr ;
@@ -1408,9 +1408,20 @@ auto FunctionBuilderBuilder::build(const clang::FunctionDecl *S, bool allowKerne
1408
1408
} break ;
1409
1409
}
1410
1410
stack.SetLocal (param, local);
1411
+ return local;
1411
1412
} else {
1412
1413
clangcxx_log_error (" unfound arg type: {}" , Ty.getAsString ());
1413
1414
}
1415
+ return nullptr ;
1416
+ };
1417
+ luisa::vector<const clang::VarDecl*> input_params (params.begin (), params.end ());
1418
+ if (is_kernel) {
1419
+ for (const auto *var : db->extern_vars ) {
1420
+ collect_arg (var);
1421
+ }
1422
+ }
1423
+ for (auto param : params) {
1424
+ collect_arg (param);
1414
1425
}
1415
1426
1416
1427
// ctor initializers
@@ -1468,6 +1479,17 @@ void RecordDeclStmtHandler::run(const MatchFinder::MatchResult &Result) {
1468
1479
}
1469
1480
}
1470
1481
1482
+ void ExternVarHandler::run (const MatchFinder::MatchResult &Result) {
1483
+ if (const auto *S = Result.Nodes .getNodeAs <clang::VarDecl>(" VarDecl" )) {
1484
+ bool ignore = false ;
1485
+ for (auto Anno : S->specific_attrs <clang::AnnotateAttr>())
1486
+ ignore |= isIgnore (Anno);
1487
+ if (!ignore && S->hasExternalStorage ()) {
1488
+ db->extern_vars .emplace_back (S);
1489
+ }
1490
+ }
1491
+ }
1492
+
1471
1493
void GlobalVarHandler::run (const MatchFinder::MatchResult &Result) {
1472
1494
if (const auto *S = Result.Nodes .getNodeAs <clang::VarDecl>(" VarDecl" )) {
1473
1495
bool ignore = false ;
@@ -1545,6 +1567,13 @@ ASTConsumerBase::ASTConsumerBase() {
1545
1567
unless (isExpansionInSystemHeader ()))
1546
1568
.bind (" VarDecl" ),
1547
1569
&HandlerForGlobalVar);
1570
+
1571
+ HandlerForExternlVar.db = &db;
1572
+ Matcher.addMatcher (varDecl (
1573
+ unless (isDefinition ()),
1574
+ unless (isExpansionInSystemHeader ()))
1575
+ .bind (" VarDecl" ),
1576
+ &HandlerForExternlVar);
1548
1577
}
1549
1578
1550
1579
ASTConsumerBase::~ASTConsumerBase () {
0 commit comments