@@ -177,8 +177,18 @@ CodeGenFunction::EmitNoLoopIV(const OMPLoopDirective &LD) {
177
177
// Emit the original loop indices
178
178
for (const Expr *CE : LD.counters ()) {
179
179
const auto *CEDecl = cast<VarDecl>(cast<DeclRefExpr>(CE)->getDecl ());
180
- if (!hasAddrOfLocalVar (CEDecl))
181
- EmitVarDecl (*CEDecl);
180
+ if (!hasAddrOfLocalVar (CEDecl)) {
181
+ if (CEDecl->hasLocalStorage ())
182
+ EmitVarDecl (*CEDecl);
183
+ else {
184
+ llvm::Type *CEDeclType = ConvertTypeForMem (CEDecl->getType ());
185
+ llvm::AllocaInst *LocalForGlobal =
186
+ Builder.CreateAlloca (CEDeclType, nullptr , " lglobal" );
187
+ setAddrOfLocalVar (CEDecl, Address (LocalForGlobal, CEDeclType,
188
+ getContext ().getTypeAlignInChars (
189
+ CEDecl->getType ())));
190
+ }
191
+ }
182
192
}
183
193
184
194
// Emit the preinits
@@ -541,14 +551,17 @@ bool CodeGenFunction::EmitXteamRedStmt(const Stmt *S) {
541
551
// Compute *xteam_red_local_addr + rhs_value
542
552
llvm::Value *RedRHS = nullptr ;
543
553
llvm::Type *RedVarType = ConvertTypeForMem (RedVarDecl->getType ());
544
- if (RedVarType->isFloatTy () || RedVarType->isDoubleTy ())
545
- RedRHS =
546
- Builder.CreateFAdd (Builder.CreateLoad (XteamRedLocalAddr), RHSValue);
547
- else if (RedVarType->isIntegerTy ())
548
- RedRHS =
549
- Builder.CreateAdd (Builder.CreateLoad (XteamRedLocalAddr),
550
- Builder.CreateIntCast (RHSValue, RedVarType, false ));
551
- else
554
+ if (RedVarType->isFloatTy () || RedVarType->isDoubleTy ()) {
555
+ auto RHSOp = RHSValue->getType ()->isIntegerTy ()
556
+ ? Builder.CreateUIToFP (RHSValue, RedVarType)
557
+ : Builder.CreateFPCast (RHSValue, RedVarType);
558
+ RedRHS = Builder.CreateFAdd (Builder.CreateLoad (XteamRedLocalAddr), RHSOp);
559
+ } else if (RedVarType->isIntegerTy ()) {
560
+ auto RHSOp = RHSValue->getType ()->isIntegerTy ()
561
+ ? Builder.CreateIntCast (RHSValue, RedVarType, false )
562
+ : Builder.CreateFPToUI (RHSValue, RedVarType);
563
+ RedRHS = Builder.CreateAdd (Builder.CreateLoad (XteamRedLocalAddr), RHSOp);
564
+ } else
552
565
llvm_unreachable (" Unhandled type" );
553
566
// *xteam_red_local_addr = *xteam_red_local_addr + rhs_value
554
567
Builder.CreateStore (RedRHS, XteamRedLocalAddr);
0 commit comments