[clang] [clang][CodeGen] Detect backward jumps for C lifetime markers (PR #238919)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 14:53:50 PST 2026
================
@@ -50,35 +53,110 @@ void VarBypassDetector::Init(CodeGenModule &CGM, const Stmt *Body) {
FromScopes.clear();
ToScopes.clear();
Bypasses.clear();
+ BackwardBypassedVars.clear();
+ BackwardBypassedCLs.clear();
BypassedVarsAtSource.clear();
- Scopes = {{~0U, nullptr}};
+ Scopes = {{~0U, 0, nullptr}};
+ CurEnclosingBlockScope = 0;
AlwaysBypassed = false;
+ Initialized = true;
if (!hasJumpStmts(Body))
return;
unsigned ParentScope = 0;
AlwaysBypassed = !BuildScopeInformation(CGM, Body, ParentScope);
if (!AlwaysBypassed)
- Detect();
+ Detect(CGM.getLangOpts().CPlusPlus);
+}
+
+bool VarBypassDetector::BuildScopeInformation(CodeGenModule &CGM, QualType Ty,
+ unsigned &ParentScope) {
+ while (!Ty.isNull() && Ty->isVariablyModifiedType()) {
+ const Type *T = Ty.getTypePtr();
+ if (isa<TypedefType, DecltypeType, AutoType,
+ DeducedTemplateSpecializationType, PackIndexingType>(T))
+ return true;
+ if (const auto *TOE = dyn_cast<TypeOfExprType>(T))
+ return BuildScopeInformation(CGM, TOE->getUnderlyingExpr(), ParentScope);
+ if (const auto *VAT = dyn_cast<VariableArrayType>(T)) {
+ if (const Expr *Size = VAT->getSizeExpr())
+ if (!BuildScopeInformation(CGM, Size, ParentScope))
+ return false;
+ Ty = VAT->getElementType();
+ continue;
+ }
+ if (const auto *AT = dyn_cast<ArrayType>(T)) {
+ Ty = AT->getElementType();
+ continue;
+ }
+ if (QualType Pointee = T->getPointeeType(); !Pointee.isNull()) {
+ Ty = Pointee;
+ continue;
+ }
+ if (const auto *FT = dyn_cast<FunctionType>(T)) {
+ if (const auto *FPT = dyn_cast<FunctionProtoType>(FT))
+ for (QualType ParamTy : FPT->param_types())
+ if (!BuildScopeInformation(CGM, ParamTy, ParentScope))
+ return false;
+ Ty = FT->getReturnType();
+ continue;
+ }
+ QualType Desugared = Ty.getSingleStepDesugaredType(CGM.getContext());
+ if (Desugared == Ty)
+ break;
----------------
efriedma-quic wrote:
If we hit this "break", we somehow have a variably modified type the loop doesn't handle. Which is a bug, probably.
https://github.com/llvm/llvm-project/pull/238919
More information about the cfe-commits
mailing list