From 4db2b70248686b8ac0667237768008762a66bb06 Mon Sep 17 00:00:00 2001 From: Jian Cai Date: Mon, 8 Jun 2020 11:53:23 -0700 Subject: Add a flag to debug automatic variable initialization Summary: Add -ftrivial-auto-var-init-stop-after= to limit the number of times stack variables are initialized when -ftrivial-auto-var-init= is used to initialize stack variables to zero or a pattern. This flag can be used to bisect uninitialized uses of a stack variable exposed by automatic variable initialization, such as http://crrev.com/c/2020401. Reviewers: jfb, vitalybuka, kcc, glider, rsmith, rjmccall, pcc, eugenis, vlad.tsyrklevich Reviewed By: jfb Subscribers: phosek, hubert.reinterpretcast, srhines, MaskRay, george.burgess.iv, dexonsmith, inglorion, gbiv, llozano, manojgupta, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D77168 --- clang/lib/CodeGen/CodeGenModule.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 3d7a87308128..26d34fa293e4 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6023,3 +6023,28 @@ CharUnits CodeGenModule::getNaturalTypeAlignment(QualType T, } return Alignment; } + +bool CodeGenModule::stopAutoInit() { + unsigned StopAfter = getContext().getLangOpts().TrivialAutoVarInitStopAfter; + if (StopAfter) { + // This number is positive only when -ftrivial-auto-var-init-stop-after=* is + // used + if (NumAutoVarInit >= StopAfter) { + return true; + } + if (!NumAutoVarInit) { + unsigned DiagID = getDiags().getCustomDiagID( + DiagnosticsEngine::Warning, + "-ftrivial-auto-var-init-stop-after=%0 has been enabled to limit the " + "number of times ftrivial-auto-var-init=%1 gets applied."); + getDiags().Report(DiagID) + << StopAfter + << (getContext().getLangOpts().getTrivialAutoVarInit() == + LangOptions::TrivialAutoVarInitKind::Zero + ? "zero" + : "pattern"); + } + ++NumAutoVarInit; + } + return false; +} -- cgit v1.2.3