@@ -1845,11 +1845,11 @@ void CGOpenMPRuntime::emitIfClause(CodeGenFunction &CGF, const Expr *Cond,
18451845  CGF.EmitBlock(ContBlock, /*IsFinished=*/true);
18461846}
18471847
1848- void CGOpenMPRuntime::emitParallelCall(CodeGenFunction &CGF, SourceLocation Loc, 
1849-                                         llvm::Function *OutlinedFn,
1850-                                         ArrayRef<llvm::Value *> CapturedVars,
1851-                                        const Expr *IfCond ,
1852-                                        llvm::Value *NumThreads ) {
1848+ void CGOpenMPRuntime::emitParallelCall(
1849+     CodeGenFunction &CGF, SourceLocation Loc,  llvm::Function *OutlinedFn,
1850+     ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond ,
1851+     llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier ,
1852+     OpenMPSeverityClauseKind Severity, const Expr *Message ) {
18531853  if (!CGF.HaveInsertPoint())
18541854    return;
18551855  llvm::Value *RTLoc = emitUpdateLocation(CGF, Loc);
@@ -2372,9 +2372,8 @@ void CGOpenMPRuntime::emitBarrierCall(CodeGenFunction &CGF, SourceLocation Loc,
23722372
23732373void CGOpenMPRuntime::emitErrorCall(CodeGenFunction &CGF, SourceLocation Loc,
23742374                                    Expr *ME, bool IsFatal) {
2375-   llvm::Value *MVL =
2376-       ME ? CGF.EmitStringLiteralLValue(cast<StringLiteral>(ME)).getPointer(CGF)
2377-          : llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
2375+   llvm::Value *MVL = ME ? CGF.EmitScalarExpr(ME)
2376+                         : llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
23782377  // Build call void __kmpc_error(ident_t *loc, int severity, const char
23792378  // *message)
23802379  llvm::Value *Args[] = {
@@ -2699,18 +2698,54 @@ llvm::Value *CGOpenMPRuntime::emitForNext(CodeGenFunction &CGF,
26992698      CGF.getContext().BoolTy, Loc);
27002699}
27012700
2702- void CGOpenMPRuntime::emitNumThreadsClause(CodeGenFunction &CGF,
2703-                                            llvm::Value *NumThreads,
2704-                                            SourceLocation Loc) {
2701+ llvm::Value *CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
2702+                                                 const Expr *Message) {
2703+   if (!Message)
2704+     return llvm::ConstantPointerNull::get(CGF.VoidPtrTy);
2705+   return CGF.EmitScalarExpr(Message);
2706+ }
2707+ 
2708+ llvm::Value *
2709+ CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF,
2710+                                    const OMPMessageClause *MessageClause) {
2711+   return emitMessageClause(
2712+       CGF, MessageClause ? MessageClause->getMessageString() : nullptr);
2713+ }
2714+ 
2715+ llvm::Value *
2716+ CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) {
2717+   // OpenMP 6.0, 10.4: "If no severity clause is specified then the effect is
2718+   // as if sev-level is fatal."
2719+   return llvm::ConstantInt::get(CGM.Int32Ty,
2720+                                 Severity == OMPC_SEVERITY_warning ? 1 : 2);
2721+ }
2722+ 
2723+ llvm::Value *
2724+ CGOpenMPRuntime::emitSeverityClause(const OMPSeverityClause *SeverityClause) {
2725+   return emitSeverityClause(SeverityClause ? SeverityClause->getSeverityKind()
2726+                                            : OMPC_SEVERITY_unknown);
2727+ }
2728+ 
2729+ void CGOpenMPRuntime::emitNumThreadsClause(
2730+     CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
2731+     OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
2732+     const Expr *Message) {
27052733  if (!CGF.HaveInsertPoint())
27062734    return;
2735+   llvm::SmallVector<llvm::Value *, 4> Args(
2736+       {emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
2737+        CGF.Builder.CreateIntCast(NumThreads, CGF.Int32Ty, /*isSigned*/ true)});
27072738  // Build call __kmpc_push_num_threads(&loc, global_tid, num_threads)
2708-   llvm::Value *Args[] = {
2709-       emitUpdateLocation(CGF, Loc), getThreadID(CGF, Loc),
2710-       CGF.Builder.CreateIntCast(NumThreads, CGF.Int32Ty, /*isSigned*/ true)};
2711-   CGF.EmitRuntimeCall(OMPBuilder.getOrCreateRuntimeFunction(
2712-                           CGM.getModule(), OMPRTL___kmpc_push_num_threads),
2713-                       Args);
2739+   // or __kmpc_push_num_threads_strict(&loc, global_tid, num_threads, severity,
2740+   // messsage) if strict modifier is used.
2741+   RuntimeFunction FnID = OMPRTL___kmpc_push_num_threads;
2742+   if (Modifier == OMPC_NUMTHREADS_strict) {
2743+     FnID = OMPRTL___kmpc_push_num_threads_strict;
2744+     Args.push_back(emitSeverityClause(Severity));
2745+     Args.push_back(emitMessageClause(CGF, Message));
2746+   }
2747+   CGF.EmitRuntimeCall(
2748+       OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args);
27142749}
27152750
27162751void CGOpenMPRuntime::emitProcBindClause(CodeGenFunction &CGF,
@@ -12114,12 +12149,11 @@ llvm::Function *CGOpenMPSIMDRuntime::emitTaskOutlinedFunction(
1211412149  llvm_unreachable("Not supported in SIMD-only mode");
1211512150}
1211612151
12117- void CGOpenMPSIMDRuntime::emitParallelCall(CodeGenFunction &CGF,
12118-                                            SourceLocation Loc,
12119-                                            llvm::Function *OutlinedFn,
12120-                                            ArrayRef<llvm::Value *> CapturedVars,
12121-                                            const Expr *IfCond,
12122-                                            llvm::Value *NumThreads) {
12152+ void CGOpenMPSIMDRuntime::emitParallelCall(
12153+     CodeGenFunction &CGF, SourceLocation Loc, llvm::Function *OutlinedFn,
12154+     ArrayRef<llvm::Value *> CapturedVars, const Expr *IfCond,
12155+     llvm::Value *NumThreads, OpenMPNumThreadsClauseModifier NumThreadsModifier,
12156+     OpenMPSeverityClauseKind Severity, const Expr *Message) {
1212312157  llvm_unreachable("Not supported in SIMD-only mode");
1212412158}
1212512159
@@ -12222,9 +12256,10 @@ llvm::Value *CGOpenMPSIMDRuntime::emitForNext(CodeGenFunction &CGF,
1222212256  llvm_unreachable("Not supported in SIMD-only mode");
1222312257}
1222412258
12225- void CGOpenMPSIMDRuntime::emitNumThreadsClause(CodeGenFunction &CGF,
12226-                                                llvm::Value *NumThreads,
12227-                                                SourceLocation Loc) {
12259+ void CGOpenMPSIMDRuntime::emitNumThreadsClause(
12260+     CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc,
12261+     OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity,
12262+     const Expr *Message) {
1222812263  llvm_unreachable("Not supported in SIMD-only mode");
1222912264}
1223012265
0 commit comments