Skip to content

Commit

Permalink
Bug fixes for rebase onto LLVM 19.
Browse files Browse the repository at this point in the history
  • Loading branch information
neboat committed Jan 15, 2025
1 parent 4093f20 commit b316798
Show file tree
Hide file tree
Showing 120 changed files with 621 additions and 459 deletions.
13 changes: 8 additions & 5 deletions clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,19 +1385,22 @@ def is_unexposed(self):
OPEN_ACC_COMPUTE_DIRECTIVE = 320

# Cilk cilk_spawn statement.
CILK_SPAWN_STMT = 321
CILK_SPAWN_STMT = 322

# Cilk wrapper for an expression preceded by cilk_spawn.
CILK_SPAWN_EXPR = 322
CILK_SPAWN_EXPR = 323

# Cilk cilk_sync statement.
CILK_SYNC_STMT = 323
CILK_SYNC_STMT = 324

# Cilk cilk_for statement.
CILK_FOR_STMT = 324
CILK_FOR_STMT = 325

# Cilk cilk_scope statement.
CILK_SCOPE_STMT = 325
CILK_SCOPE_STMT = 326

# Cilk cilk_for range statement.
CILK_FOR_RANGE_STMT = 327

###
# Other Kinds
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang-c/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -2180,11 +2180,11 @@ enum CXCursorKind {

/** A _Cilk_scope statement.
*/
CXCursor_CilkScopeStmt = 311,
CXCursor_CilkScopeStmt = 326,

/** A _Cilk_for range statement.
*/
CXCursor_CilkForRangeStmt = 312,
CXCursor_CilkForRangeStmt = 327,

CXCursor_LastStmt = CXCursor_CilkForRangeStmt,

Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,17 @@ def err_drv_invalid_cf_runtime_abi
def err_drv_gnustep_objc_runtime_incompatible_binary : Error<
"GNUstep Objective-C runtime version %0 incompatible with target binary format">;
def err_drv_double_cilk : Error<
"Conflicting Cilk versions">;
"conflicting Cilk versions">;
def err_drv_cilk_objc : Error<
"Cilk does not support Objective-C">;
def err_drv_cilk_unsupported: Error<
"Cilk not yet supported for this target">;
def err_drv_opencilk_missing_abi_bitcode: Error<
"Cannot find OpenCilk runtime ABI bitcode file: %0">;
"cannot find OpenCilk runtime ABI bitcode file: %0">;
def err_drv_opencilk_resource_dir_missing_include: Error<
"No include directory in OpenCilk resource directory: %0">;
"no include directory in OpenCilk resource directory: %0">;
def err_drv_opencilk_resource_dir_missing_lib: Error<
"No lib directory in OpenCilk resource directory: %0">;
"no lib directory in OpenCilk resource directory: %0">;
def err_drv_emit_llvm_link : Error<
"-emit-llvm cannot be used when linking">;
def err_drv_optimization_remark_pattern : Error<
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace clang {
DIAG_SIZE_AST = 300,
DIAG_SIZE_COMMENT = 100,
DIAG_SIZE_CROSSTU = 100,
DIAG_SIZE_SEMA = 4500,
DIAG_SIZE_SEMA = 4600,
DIAG_SIZE_ANALYSIS = 100,
DIAG_SIZE_REFACTORING = 1000,
DIAG_SIZE_INSTALLAPI = 100,
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ def warn_pragma_cilk_grainsize_equals: Warning<
"'#pragma cilk grainsize' no longer requires '='">,
InGroup<SourceUsesCilkPlus>;
def warn_cilk_for_forrange_loop_experimental: Warning<
"'cilk_for' support for for-range loops is currently EXPERIMENTAL only!">,
"'cilk_for' support for for-range loops is currently experimental">,
InGroup<SourceUsesCilkPlus>;
def error_hyperobject_arguments: Error<
"hyperobject must have 0 or 2 callbacks">;
Expand Down
8 changes: 4 additions & 4 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11054,11 +11054,11 @@ def err_cilk_for_increment_inconsistent : Error<
def err_cilk_for_increment_zero : Error<
"loop increment must be non-zero in 'cilk_for'">;
def err_cilk_for_loop_modifies_control_var : Error<
"Modifying the loop control variable inside a 'cilk_for' has undefined behavior">;
"modifying the loop control variable inside a 'cilk_for' has undefined behavior">;
def warn_cilk_for_loop_control_var_func : Warning<
"Modifying the loop control variable inside a 'cilk_for' using a function call has undefined behavior">, InGroup<CilkPlusLoopControlVarModification>, DefaultIgnore;
"modifying the loop control variable inside a 'cilk_for' using a function call has undefined behavior">, InGroup<CilkPlusLoopControlVarModification>, DefaultIgnore;
def warn_cilk_for_loop_control_var_aliased: Warning<
"Modifying the loop control variable '%0' through an alias in 'cilk_for' has undefined behavior">, InGroup<CilkPlusLoopControlVarModification>, DefaultIgnore;
"modifying the loop control variable '%0' through an alias in 'cilk_for' has undefined behavior">, InGroup<CilkPlusLoopControlVarModification>, DefaultIgnore;
def note_cilk_for_loop_control_var_declared_here: Note<
"'cilk_for' loop control variable declared here">;
def warn_empty_cilk_for_body : Warning<
Expand Down Expand Up @@ -11140,7 +11140,7 @@ def no_reducer_array : Warning<

// cilk for_range
def err_cilk_for_range_end_minus_begin : Error<
"Cannot determine length with '__end - __begin'. Please use a random access iterator.">;
"cannot determine length with '__end - __begin'; please use a random access iterator">;
}
// end of Cilk category

Expand Down
13 changes: 13 additions & 0 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3194,6 +3194,19 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
OS << "P";
return;

case Type::Hyperobject: {
const auto *HT = cast<HyperobjectType>(T);
OS << "<hyperobject>";
encodeTypeForFunctionPointerAuth(Ctx, OS, HT->getElementType());
if (HT->hasCallbacks()) {
OS << "<identity>";
encodeTypeForFunctionPointerAuth(Ctx, OS, HT->getIdentity()->getType());
OS << "<reduce>";
encodeTypeForFunctionPointerAuth(Ctx, OS, HT->getReduce()->getType());
}
return;
}

case Type::ObjCObjectPointer:
case Type::BlockPointer:
OS << "P";
Expand Down
32 changes: 27 additions & 5 deletions clang/lib/CodeGen/CGCilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void CodeGenFunction::DetachScope::FinishDetach() {
}
}

Address CodeGenFunction::DetachScope::CreateDetachedMemTemp(
RawAddress CodeGenFunction::DetachScope::CreateDetachedMemTemp(
QualType Ty, StorageDuration SD, const Twine &Name) {
// There shouldn't be multiple reference temporaries needed.
assert(!RefTmp.isValid() &&
Expand Down Expand Up @@ -425,7 +425,7 @@ llvm::Instruction *CodeGenFunction::EmitSyncRegionStart() {
auto NL = ApplyDebugLocation::CreateArtificial(*this);
llvm::Instruction *SRStart = llvm::CallInst::Create(
CGM.getIntrinsic(llvm::Intrinsic::syncregion_start),
"syncreg", AllocaInsertPt);
"syncreg", &*AllocaInsertPt);
SRStart->setDebugLoc(Builder.getCurrentDebugLocation());
return SRStart;
}
Expand Down Expand Up @@ -858,6 +858,30 @@ LValue CodeGenFunction::EmitCilkSpawnExprLValue(const CilkSpawnExpr *E) {
return LV;
}

// Copied from CGStmt.cpp
// [C++26][stmt.iter.general] (DR)
// A trivially empty iteration statement is an iteration statement matching one
// of the following forms:
// - while ( expression ) ;
// - while ( expression ) { }
// - do ; while ( expression ) ;
// - do { } while ( expression ) ;
// - for ( init-statement expression(opt); ) ;
// - for ( init-statement expression(opt); ) { }
template <typename LoopStmt> static bool hasEmptyLoopBody(const LoopStmt &S) {
if constexpr (std::is_same_v<LoopStmt, ForStmt> ||
std::is_same_v<LoopStmt, CilkForStmt>) {
if (S.getInc())
return false;
}
const Stmt *Body = S.getBody();
if (!Body || isa<NullStmt>(Body))
return true;
if (const CompoundStmt *Compound = dyn_cast<CompoundStmt>(Body))
return Compound->body_empty();
return false;
}

void CodeGenFunction::EmitCilkForStmt(const CilkForStmt &S,
ArrayRef<const Attr *> ForAttrs) {
JumpDest LoopExit = getJumpDestInCurrentScope("pfor.end");
Expand Down Expand Up @@ -918,14 +942,12 @@ void CodeGenFunction::EmitCilkForStmt(const CilkForStmt &S,
EmitBlock(CondBlock);

Expr::EvalResult Result;
bool CondIsConstInt = S.getCond()->EvaluateAsInt(Result, getContext());

LoopStack.setSpawnStrategy(LoopAttributes::DAC);
const SourceRange &R = S.getSourceRange();
LoopStack.push(CondBlock, CGM.getContext(), CGM.getCodeGenOpts(), ForAttrs,
SourceLocToDebugLoc(R.getBegin()),
SourceLocToDebugLoc(R.getEnd()),
checkIfLoopMustProgress(CondIsConstInt));
checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S)));

const Expr *Inc = S.getInc();
assert(Inc && "_Cilk_for loop has no increment");
Expand Down
13 changes: 5 additions & 8 deletions clang/lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1899,7 +1899,7 @@ void CodeGenFunction::destroyHyperobject(CodeGenFunction &CGF, Address Addr,
QualType Type) {
llvm::Function *F = CGF.CGM.getIntrinsic(llvm::Intrinsic::reducer_unregister);
llvm::Value *Arg =
CGF.Builder.CreateBitCast(Addr.getPointer(), CGF.CGM.VoidPtrTy);
CGF.Builder.CreateBitCast(Addr.emitRawPointer(CGF), CGF.CGM.VoidPtrTy);
CGF.Builder.CreateCall(F, {Arg});
QualType Inner = Type.stripHyperobject();
if (const RecordType *rtype = Inner->getAs<RecordType>()) {
Expand Down Expand Up @@ -2015,7 +2015,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
initializeWhatIsTechnicallyUninitialized(Loc);
if (Reducer)
EmitReducerInit(&D, RCB,
Builder.CreateBitCast(emission.Addr.getPointer(),
Builder.CreateBitCast(emission.Addr.emitRawPointer(*this),
CGM.VoidPtrTy));
return;
}
Expand Down Expand Up @@ -2075,7 +2075,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
EmitExprAsInit(Init, &D, lv, capturedByInit);
if (Reducer)
EmitReducerInit(&D, RCB,
Builder.CreateBitCast(emission.Addr.getPointer(),
Builder.CreateBitCast(emission.Addr.emitRawPointer(*this),
CGM.VoidPtrTy));
return;
}
Expand All @@ -2087,7 +2087,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
EmitStoreThroughLValue(RValue::get(constant), lv, true);
if (Reducer)
EmitReducerInit(&D, RCB,
Builder.CreateBitCast(emission.Addr.getPointer(),
Builder.CreateBitCast(emission.Addr.emitRawPointer(*this),
CGM.VoidPtrTy));
return;
}
Expand All @@ -2098,7 +2098,7 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {

if (Reducer)
EmitReducerInit(&D, RCB,
Builder.CreateBitCast(emission.Addr.getPointer(),
Builder.CreateBitCast(emission.Addr.emitRawPointer(*this),
CGM.VoidPtrTy));
}

Expand Down Expand Up @@ -2325,9 +2325,6 @@ void CodeGenFunction::pushDestroy(QualType::DestructionKind dtorKind,
void CodeGenFunction::pushDestroy(CleanupKind cleanupKind, Address addr,
QualType type, Destroyer *destroyer,
bool useEHCleanupForArray) {
if (SpawnedCleanup)
return pushLifetimeExtendedDestroy(cleanupKind, addr, type, destroyer,
useEHCleanupForArray);
pushFullExprCleanup<DestroyObject>(cleanupKind, addr, type,
destroyer, useEHCleanupForArray);
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CodeGen/CGDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,9 @@ llvm::Function *CodeGenFunction::generateDestroyHelper(

if (IsReducer) {
llvm::Function *Unregister =
CGM.getIntrinsic(llvm::Intrinsic::reducer_unregister);
CGM.getIntrinsic(llvm::Intrinsic::reducer_unregister);
llvm::Value *AddrVoid =
Builder.CreateBitCast(addr.getPointer(), CGM.VoidPtrTy);
Builder.CreateBitCast(addr.emitRawPointer(*this), CGM.VoidPtrTy);
Builder.CreateCall(Unregister, {AddrVoid});
}

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ class CodeGenFunction : public CodeGenTypeCache {

// Information about a reference temporary created early in the detached
// block.
Address RefTmp = Address::invalid();
RawAddress RefTmp = RawAddress::invalid();
StorageDuration RefTmpSD;

// Optional taskframe created separately from detach.
Expand Down Expand Up @@ -1661,8 +1661,8 @@ class CodeGenFunction : public CodeGenTypeCache {

// Create a temporary for the spawned task, specifically, before the spawned
// task has started.
Address CreateDetachedMemTemp(QualType Ty, StorageDuration SD,
const Twine &Name = "det.tmp");
RawAddress CreateDetachedMemTemp(QualType Ty, StorageDuration SD,
const Twine &Name = "det.tmp");
};

/// The current detach scope.
Expand Down
9 changes: 6 additions & 3 deletions clang/lib/Parse/ParseCilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {

if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_ForInit);
Actions.CodeCompletion().CodeCompleteOrdinaryName(
getCurScope(), SemaCodeCompletion::PCC_ForInit);
return StmtError();
}

Expand Down Expand Up @@ -281,7 +282,8 @@ StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {

if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCForCollection(getCurScope(), DG);
Actions.CodeCompletion().CodeCompleteObjCForCollection(getCurScope(),
DG);
return StmtError();
}
Collection = ParseExpression();
Expand Down Expand Up @@ -318,7 +320,8 @@ StmtResult Parser::ParseCilkForStatement(SourceLocation *TrailingElseLoc) {

if (Tok.is(tok::code_completion)) {
cutOffParsing();
Actions.CodeCompleteObjCForCollection(getCurScope(), nullptr);
Actions.CodeCompletion().CodeCompleteObjCForCollection(getCurScope(),
nullptr);
return StmtError();
}
Collection = ParseExpression();
Expand Down
19 changes: 11 additions & 8 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2290,9 +2290,10 @@ Expr *Sema::BuildHyperobjectLookup(Expr *E, bool Pointer) {
InputType.getLocalFastQualifiers());
QualType Ptr = Context.getPointerType(ResultType);

SourceLocation Loc = E->getExprLoc();
ExprResult SizeExpr;
if (ResultType.getTypePtr()->isDependentType()) {
SizeExpr = CreateUnaryExprOrTypeTraitExpr(E, E->getExprLoc(), UETT_SizeOf);
SizeExpr = CreateUnaryExprOrTypeTraitExpr(E, Loc, UETT_SizeOf);
} else {
QualType SizeType = Context.getSizeType();
llvm::APInt Size(Context.getTypeSize(SizeType),
Expand All @@ -2305,7 +2306,7 @@ Expr *Sema::BuildHyperobjectLookup(Expr *E, bool Pointer) {
VarAddr = E;
} else if (Difficult) {
ExprResult Address =
BuildBuiltinCallExpr(E->getExprLoc(), Builtin::BI__builtin_addressof, E);
BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_addressof, E);
assert(Address.isUsable());
VarAddr = Address.get();
} else {
Expand All @@ -2316,16 +2317,18 @@ Expr *Sema::BuildHyperobjectLookup(Expr *E, bool Pointer) {
Expr *CallArgs[] = {VarAddr, SizeExpr.get(), HT->getIdentity(),
HT->getReduce()};
ExprResult Call =
BuildBuiltinCallExpr(E->getExprLoc(), Builtin::BI__hyper_lookup, CallArgs);
BuildBuiltinCallExpr(Loc, Builtin::BI__hyper_lookup, CallArgs);

// Template expansion normally strips out implicit casts, so make this
// explicit in C++.
CastExpr *Casted = nullptr;
Expr *Casted = nullptr;
if (Difficult)
Casted = CXXStaticCastExpr::Create(
Context, Ptr, VK_PRValue, CK_BitCast, Call.get(), nullptr,
Context.CreateTypeSourceInfo(Ptr), FPOptionsOverride(),
SourceLocation(), SourceLocation(), SourceRange());
// Based on logic in CoroutineStmtBuilder::makeNewAndDeleteExpr()
Casted =
BuildCXXNamedCast(Loc, tok::kw_static_cast,
Context.getTrivialTypeSourceInfo(Ptr), Call.get(),
SourceRange(Loc, Loc), SourceRange(Loc, Loc))
.get();
else
Casted =
ImplicitCastExpr::Create(Context, Ptr, CK_BitCast, Call.get(), nullptr,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
.Default(LoopHintAttr::TapirGrainsize);
if (Option == LoopHintAttr::TapirGrainsize) {
assert(ValueExpr && "Attribute must have a valid value expression.");
if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc()))
if (S.CheckLoopHintExpr(ValueExpr, St->getBeginLoc(), /*AllowZero=*/true))
return nullptr;
State = LoopHintAttr::Numeric;
} else
Expand Down
Loading

0 comments on commit b316798

Please sign in to comment.