aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/UninitializedValues.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-27[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)Matheus Izvekov1-1/+1
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`, as a redirection to `TypeBase.h`, and redirects most users to include the former instead. This is a preparatory patch for being able to provide inline definitions for `Type` methods which would otherwise cause a circular dependency with `Decl{,CXX}.h`. Doing these operations into their own NFC patch helps the git rename detection logic work, preserving the history. This patch makes clang just a little slower to build (~0.17%), just because it makes more code indirectly include `DeclCXX.h`.
2025-08-27[clang] NFC: rename clang/include/clang/AST/Type.h to TypeBase.h (#155049)Matheus Izvekov1-1/+1
This is a preparatory patch, to be able to provide inline definitions for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also depends on `Type.h`, this would not be possible without some reorganizing. Splitting this rename into its own patch allows git to track this as a rename, and preserve all git history, and not force any code reformatting. A later NFC patch will reintroduce `Type.h` as redirection to `TypeBase.h`, rewriting most places back to directly including `Type.h` instead of `TypeBase.h`, leaving only a handful of places where this is necessary. Then yet a later patch will exploit this by making more stuff inline.
2025-07-14[clang] Fix -Wuninitialized for values passed by const pointers (#147221)Igor Kudrin1-2/+0
This enables producing a "variable is uninitialized" warning when a value is passed to a pointer-to-const argument: ``` void foo(const int *); void test() { int *v; foo(v); } ``` Fixes #37460
2025-07-14[clang] Add -Wuninitialized-const-pointer (#148337)Igor Kudrin1-9/+17
This option is similar to -Wuninitialized-const-reference, but diagnoses the passing of an uninitialized value via a const pointer, like in the following code: ``` void foo(const int *); void test() { int v; foo(&v); } ``` This is an extract from #147221 as suggested in [this comment](https://github.com/llvm/llvm-project/pull/147221#discussion_r2190998730).
2025-07-10[clang] Combine ConstRefUse with other warnings for uninitialized values ↵Igor Kudrin1-8/+5
(#147898) This helps to avoid duplicating warnings in cases like: ``` > cat test.cpp void bar(int); void foo(const int &); void test(bool a) { int v = v; if (a) bar(v); else foo(v); } > clang++.exe test.cpp -fsyntax-only -Wuninitialized test.cpp:4:11: warning: variable 'v' is uninitialized when used within its own initialization [-Wuninitialized] 4 | int v = v; | ~ ^ test.cpp:4:11: warning: variable 'v' is uninitialized when used within its own initialization [-Wuninitialized] 4 | int v = v; | ~ ^ 2 warnings generated. ```
2025-07-10[clang][NFC] Remove an unused parameter in CFGBlockValues::getValue() (#147897)Igor Kudrin1-6/+6
The second parameter is unused since 6080d32194.
2025-05-31[Analysis] Remove unused includes (NFC) (#142255)Kazu Hirata1-2/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-02-08[Analysis] Avoid repeated hash lookups (NFC) (#126378)Kazu Hirata1-2/+4
2024-04-18[clang][NFC] Fix FieldDecl::isUnnamedBitfield() capitalization (#89048)Timm Baeder1-1/+1
We always capitalize bitfield as "BitField".
2023-12-08[RISCV] Remove Type::isRVVType() and replace with ↵Craig Topper1-1/+1
isRVVSizelessBuiltinType(). NFC These both do the same thing, but some profiling on a Releast+Asserts build suggests isRVVSizelessBuiltinType() is the more efficient version so lets keep that one.
2023-06-26[clang][NFC] Remove trailing whitespaces and enforce it in lib, include and docsNikolas Klauser1-1/+1
A lot of editors remove trailing whitespaces. This patch removes any trailing whitespaces and makes sure that no new ones are added. Reviewed By: erichkeane, paulkirth, #libc, philnik Spies: wangpc, aheejin, MaskRay, pcwang-thead, cfe-commits, libcxx-commits, dschuff, nemanjai, arichardson, kbarton, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, Jim, s.egerton, sameer.abuasal, apazos, luismarques, martong, frasercrmck, steakhal, luke Differential Revision: https://reviews.llvm.org/D151963
2023-06-15No longer diagnose (functionally) empty structures under -WuninitializedAaron Ballman1-4/+22
An empty structure in C has no way to be initialized, so triggering a -Wuninitialized warning for a variable of empty structure type is not actionable for users. This silences the false positive warning, which matches the behavior of GCC as well. We no longer diagnose if the structure has no members, or has only zero-sized members (unnamed bit-fields, zero-sized bit-fields, empty structure types). Fixes: https://github.com/llvm/llvm-project/issues/26842
2023-02-16[clang] fix -Wuninitialized for asm goto outputs on indirect edges.Nick Desaulniers1-23/+2
Now that we support outputs from asm goto along indirect edges, we can remove/revert some code that was added to help warn about the previous limitation that outputs were not supported along indirect edges. Reverts some code added in: commit 72aa619a7fe0 ("Warn of uninitialized variables on asm goto's indirect branch") commit 3a604fdbcd5f ("[Clang][CFG] check children statements of asm goto") But keeps+updates the tests. Link: https://github.com/llvm/llvm-project/issues/53562 Reviewed By: void Differential Revision: https://reviews.llvm.org/D140508
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes several "using" declarations and #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-4/+4
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-17llvm::Optional::value => operator*/operator->Fangrui Song1-6/+3
std::optional::value() has undesired exception checking semantics and is unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The call sites block std::optional migration. This makes `ninja clang` work in the absence of llvm::Optional::value.
2022-12-08[clang] Don't including None.h (NFC)Kazu Hirata1-1/+0
These source files no longer use None, so they do not need to include None.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[Analysis] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-24[RISCV][clang] Support RISC-V vectors in UninitializedValues.Craig Topper1-1/+2
RISC-V vectors are basically vectors, but we use builtin types to restrict the possible types. Treat them the same as vectors and scalars for this analysis. Reviewed By: reames Differential Revision: https://reviews.llvm.org/D136511
2022-07-13[clang] Use value instead of getValue (NFC)Kazu Hirata1-2/+2
2022-06-25[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-4/+4
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-4/+4
2022-01-07[Clang][CFG] check children statements of asm gotoNick Desaulniers1-5/+4
When performing CFG based analyses, don't forget to check the child statements of an asm goto, such as the expressions used for inputs+outputs. Fixes: https://github.com/llvm/llvm-project/issues/51024 Fixes: https://github.com/ClangBuiltLinux/linux/issues/1439 Reviewed By: void, jyknight, jyu2, efriedma Differential Revision: https://reviews.llvm.org/D116059
2021-12-07[Analysis] Ignore casts and unary ops for uninitialized valuesBill Wendling1-4/+13
A series of unary operators and casts may obscure the variable we're trying to analyze. Ignore them for the uninitialized value analysis. Other checks determine if the unary operators result in a valid l-value. Link: https://github.com/ClangBuiltLinux/linux/issues/1521 Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D114848
2020-07-06[SemaCXX] Fix false positive of -Wuninitialized-const-reference in empty ↵Zequan Wu1-2/+11
function body. Summary: Some libraries use empty function to ignore unused variable warnings, which gets a new warning from `-Wuninitialized-const-reference`, discussed here https://reviews.llvm.org/D79895#2107604. This patch should fix that. Reviewers: hans, nick, aaron.ballman Reviewed By: aaron.ballman Subscribers: aaron.ballman, riccibruno, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82425
2020-06-02[Sema] Use isAlwaysUninit for -Wuninitialized-const-reference after D79895Fangrui Song1-1/+1
2020-06-02[Clang] Add a new warning to warn when passing uninitialized variables as ↵Zequan Wu1-3/+22
const reference parameters to a function Summary: Add a new warning -Wuninitialized-const-reference as a subgroup of -Wuninitialized to address a bug filed here: https://bugs.llvm.org/show_bug.cgi?id=45624 This warning is controlled by -Wuninitialized and can be disabled by -Wno-uninitialized-const-reference. The warning is diagnosed when passing uninitialized variables as const reference parameters to a function. Differential Revision: https://reviews.llvm.org/D79895
2020-03-10Warn of uninitialized variables on asm goto's indirect branchBill Wendling1-2/+28
Summary: Outputs from an asm goto block cannot be used on the indirect branch. It's not supported and may result in invalid code generation. Reviewers: jyknight, nickdesaulniers, hfinkel Reviewed By: nickdesaulniers Subscribers: martong, cfe-commits, rnk, craig.topper, hiraditya, rsmith Tags: #clang Differential Revision: https://reviews.llvm.org/D71314
2020-02-25[Analysis] Fix -Wrange-loop-analysis after D69876Fangrui Song1-1/+1
2020-02-24Support output constraints on "asm goto"Bill Wendling1-0/+15
Summary: Clang's "asm goto" feature didn't initially support outputs constraints. That was the same behavior as gcc's implementation. The decision by gcc not to support outputs was based on a restriction in their IR regarding terminators. LLVM doesn't restrict terminators from returning values (e.g. 'invoke'), so it made sense to support this feature. Output values are valid only on the 'fallthrough' path. If an output value's used on an indirect branch, then it's 'poisoned'. In theory, outputs *could* be valid on the 'indirect' paths, but it's very difficult to guarantee that the original semantics would be retained. E.g. because indirect labels could be used as data, we wouldn't be able to split critical edges in situations where two 'callbr' instructions have the same indirect label, because the indirect branch's destination would no longer be the same. Reviewers: jyknight, nickdesaulniers, hfinkel Reviewed By: jyknight, nickdesaulniers Subscribers: MaskRay, rsmith, hiraditya, llvm-commits, cfe-commits, craig.topper, rnk Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D69876
2020-01-17[DataFlow] Factor two worklist implementations outGabor Horvath1-63/+2
Right now every dataflow algorithm uses its own worklist implementation. This is a first step to reduce this duplication. Some upcoming algorithms such as the lifetime analysis is going to use the factored out implementations. Differential Revision: https://reviews.llvm.org/D72380
2019-07-11[OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP ↵Alexey Bataev1-0/+17
programs. Summary: Some OpenMP clauses rely on the values of the variables. If the variable is not initialized and used in OpenMP clauses that depend on the variables values, it should be reported that the uninitialized variable is used in the OpenMP clause expression. This patch adds initial processing for uninitialized variables in OpenMP constructs. Currently, it checks for use of the uninitialized variables in the structured blocks. Reviewers: NoQ, Szelethus, dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet Subscribers: rnkovacs, guansong, jfb, jdoerfert, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64356 llvm-svn: 365786
2019-05-24[CFG] NFC: Remove implicit conversion from CFGTerminator to Stmt *.Artem Dergachev1-1/+1
Turn it into a variant class instead. This conversion does indeed save some code but there's a plan to add support for more kinds of terminators that aren't necessarily based on statements, and with those in mind it becomes more and more confusing to have CFGTerminators implicitly convertible to a Stmt *. Differential Revision: https://reviews.llvm.org/D61814 llvm-svn: 361586
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-07-30Remove trailing spaceFangrui Song1-11/+11
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
2018-03-21[Analysis] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-75/+95
other minor fixes (NFC). llvm-svn: 328063
2017-09-28Consolidate std::move() detection code. No behavior change.Nico Weber1-10/+5
llvm-svn: 314427
2017-09-06[CSA] [NFC] Move AnalysisContext.h to AnalysisDeclContext.hGeorge Karpenkov1-1/+1
The implementation is in AnalysisDeclContext.cpp and the class is called AnalysisDeclContext. Making those match up has numerous benefits, including: - Easier jump from header to/from implementation. - Easily identify filename from class. Differential Revision: https://reviews.llvm.org/D37500 llvm-svn: 312671
2016-10-29NFC small formatPiotr Padlewski1-1/+2
llvm-svn: 285496
2015-10-20Roll-back r250822.Angel Garcia Gomez1-2/+2
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez1-2/+2
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-5/+5
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-5/+5
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
2015-04-27PR23334: Perform semantic checking of lambda capture initialization in the ↵Richard Smith1-1/+1
right context. Previously we'd try to perform checks on the captures from the middle of parsing the lambda's body, at the point where we detected that a variable needed to be captured. This was wrong in a number of subtle ways. In PR23334, we couldn't correctly handle the list of potential odr-uses resulting from the capture, and our attempt to recover from that resulted in a use-after-free. We now defer building the initialization expression until we leave the lambda body and return to the enclosing context, where the initialization does the right thing. This patch only covers lambda-expressions, but we should apply the same change to blocks and captured statements too. llvm-svn: 235921
2015-04-11Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko1-1/+1
Summary: The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix Reviewers: dblaikie Reviewed By: dblaikie Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D8926 llvm-svn: 234678
2015-03-03Make -Wuninitialized warn on pointer-to-member and comma operators.Manuel Klimek1-11/+44
`isTrackedVar` has been updated to also track records. `DeclRefExpr`s appearing on the left side of a comma operator are ignored, while those appearing on the right side are classified as `Use`. Patch by Enrico Pertoso. llvm-svn: 231068
2014-11-27When checking for uninitialized values, do not confuse "std::move" with everyRichard Trieu1-1/+2
other function named "move". llvm-svn: 222863