@@ -487,23 +487,37 @@ class FunctionFilteringPass
487
487
}
488
488
489
489
// We don't actually need the proper initialization, but rather just
490
- // maintain the basic form of these operands. We create 1-bit placeholder
491
- // allocas that we "typecast" to the expected type and replace all uses.
492
- // Using fir.undefined here instead is not possible because these variables
493
- // cannot be constants, as that would trigger different codegen for target
494
- // regions.
490
+ // maintain the basic form of these operands. Generally, we create 1-bit
491
+ // placeholder allocas that we "typecast" to the expected type and replace
492
+ // all uses. Using fir.undefined here instead is not possible because these
493
+ // variables cannot be constants, as that would trigger different codegen
494
+ // for target regions.
495
495
applyChildRewrites (region, childValRewrites, rewriteValues,
496
496
parentValRewrites);
497
497
for (Value value : rewriteValues) {
498
498
Location loc = value.getLoc ();
499
499
Value rewriteValue;
500
- // If it's defined by fir.address_of, then we need to keep that op as
501
- // well because it might be pointing to a 'declare target' global.
502
- // Constants can also trigger different codegen paths, so we keep them as
503
- // well.
504
500
if (isa_and_present<arith::ConstantOp, fir::AddrOfOp>(
505
501
value.getDefiningOp ())) {
502
+ // If it's defined by fir.address_of, then we need to keep that op as
503
+ // well because it might be pointing to a 'declare target' global.
504
+ // Constants can also trigger different codegen paths, so we keep them
505
+ // as well.
506
506
rewriteValue = builder.clone (*value.getDefiningOp ())->getResult (0 );
507
+ } else if (auto boxCharType =
508
+ dyn_cast<fir::BoxCharType>(value.getType ())) {
509
+ // !fir.boxchar types cannot be directly obtained by converting a
510
+ // !fir.ref<i1>, as they aren't reference types. Since they can appear
511
+ // representing some `target firstprivate` clauses, we need to create
512
+ // a special case here based on creating a placeholder fir.emboxchar op.
513
+ MLIRContext *ctx = &getContext ();
514
+ fir::KindTy kind = boxCharType.getKind ();
515
+ auto placeholder = builder.create <fir::AllocaOp>(
516
+ loc, fir::CharacterType::getSingleton (ctx, kind));
517
+ auto one = builder.create <arith::ConstantOp>(
518
+ loc, builder.getI32Type (), builder.getI32IntegerAttr (1 ));
519
+ rewriteValue = builder.create <fir::EmboxCharOp>(loc, boxCharType,
520
+ placeholder, one);
507
521
} else {
508
522
Value placeholder =
509
523
builder.create <fir::AllocaOp>(loc, builder.getI1Type ());
0 commit comments