-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LTO] Fix used before intialised warning #143705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For whatever reason I can't reproduce this locally but I can on Compiler Explorer (https://godbolt.org/z/nfv4b83q6) and on our flang gcc bot (https://lab.llvm.org/buildbot/#/builders/130/builds/13683/steps/5/logs/stdio). In file included from ../llvm-project/llvm/include/llvm/LTO/LTO.h:33, from ../llvm-project/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:29: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy()’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:275:33: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized] 275 | ImportListsTy() : EmptyList(ImportIDs) {} | ^~~~~~~~~ ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy(size_t)’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:276:44: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized] 276 | ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {} | ^~~~~~~~~ ImportIDs was being used during construction of EmptyList, before ImportIDs itself had been constructed.
@llvm/pr-subscribers-llvm-transforms Author: David Spickett (DavidSpickett) ChangesFor whatever reason I can't reproduce this locally but I can on Compiler Explorer (https://godbolt.org/z/nfv4b83q6) and on our flang gcc bot (https://lab.llvm.org/buildbot/#/builders/130/builds/13683/steps/5/logs/stdio). In file included from ../llvm-project/llvm/include/llvm/LTO/LTO.h:33, ImportIDs was being used during construction of EmptyList, before ImportIDs itself had been constructed. Full diff: https://github.com/llvm/llvm-project/pull/143705.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
index 65228bb65ba8b..e6ae9ee831d50 100644
--- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h
+++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h
@@ -272,8 +272,9 @@ class FunctionImporter {
// A map from destination modules to lists of imports.
class ImportListsTy {
public:
- ImportListsTy() : EmptyList(ImportIDs) {}
- ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {}
+ ImportListsTy() : ImportIDs(), EmptyList(ImportIDs) {}
+ ImportListsTy(size_t Size)
+ : ImportIDs(), EmptyList(ImportIDs), ListsImpl(Size) {}
ImportMapTy &operator[](StringRef DestMod) {
return ListsImpl.try_emplace(DestMod, ImportIDs).first->second;
@@ -293,9 +294,9 @@ class FunctionImporter {
const_iterator end() const { return ListsImpl.end(); }
private:
+ ImportIDTable ImportIDs;
ImportMapTy EmptyList;
DenseMap<StringRef, ImportMapTy> ListsImpl;
- ImportIDTable ImportIDs;
};
/// The set contains an entry for every global value that the module exports.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
FWIW, building LLVM with GCC (with modern versions) products loads of warnings. It has never been entirely free of warnings, but it used to be half a dozen or so. I haven’t tried to get rid of the ones that have popped up lately, so there’s quite many these days. If you have time, there may be many more that might be similarly low hanging fruit to silence. |
Most recent I have to hand is gcc 13, and I built just llvm here:
Dangling reference to temporary I can't tell whether this is real or not, or whether there's a pattern we could use to make it know that it's not dangling. Same deal for the array bounds, they look ok to me. Fixed the dwarf linker one. Maybe gcc 15 has improved the detection for these. Some of them are from inlined versions of functions which makes it hard to unpick. |
Thanks for looking into it, and great to have it counted by category like that! If there's some GCC warning category which seems noisy and mostly has false positives, we perhaps should consider to silence that category entirely (like the array bounds)? |
Yeah could do. I'd like to understand why gcc thinks this, because it would be nicer to write it in a way that it didn't. Especially the dangling reference ones.
Should mention that this one is a false positive. |
For whatever reason I can't reproduce this locally but I can on Compiler Explorer (https://godbolt.org/z/nfv4b83q6) and on our flang gcc bot (https://lab.llvm.org/buildbot/#/builders/130/builds/13683/steps/5/logs/stdio). In file included from ../llvm-project/llvm/include/llvm/LTO/LTO.h:33, from ../llvm-project/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:29: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy()’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:275:33: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized] 275 | ImportListsTy() : EmptyList(ImportIDs) {} | ^~~~~~~~~ ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy(size_t)’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:276:44: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized] 276 | ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {} | ^~~~~~~~~ ImportIDs was being used during construction of EmptyList, before ImportIDs itself had been constructed.
For whatever reason I can't reproduce this locally but I can on Compiler Explorer (https://godbolt.org/z/nfv4b83q6) and on our flang gcc bot (https://lab.llvm.org/buildbot/#/builders/130/builds/13683/steps/5/logs/stdio). In file included from ../llvm-project/llvm/include/llvm/LTO/LTO.h:33, from ../llvm-project/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:29: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy()’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:275:33: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized] 275 | ImportListsTy() : EmptyList(ImportIDs) {} | ^~~~~~~~~ ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy(size_t)’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:276:44: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized] 276 | ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {} | ^~~~~~~~~ ImportIDs was being used during construction of EmptyList, before ImportIDs itself had been constructed.
For whatever reason I can't reproduce this locally but I can on Compiler Explorer (https://godbolt.org/z/nfv4b83q6) and on our flang gcc bot (https://lab.llvm.org/buildbot/#/builders/130/builds/13683/steps/5/logs/stdio).
In file included from ../llvm-project/llvm/include/llvm/LTO/LTO.h:33,
from ../llvm-project/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp:29:
../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy()’: ../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:275:33: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized]
275 | ImportListsTy() : EmptyList(ImportIDs) {}
| ^~~~~~~~~
../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h: In constructor ‘llvm::FunctionImporter::ImportListsTy::ImportListsTy(size_t)’:
../llvm-project/llvm/include/llvm/Transforms/IPO/FunctionImport.h:276:44: warning: member ‘llvm::FunctionImporter::ImportListsTy::ImportIDs’ is used uninitialized [-Wuninitialized]
276 | ImportListsTy(size_t Size) : EmptyList(ImportIDs), ListsImpl(Size) {}
| ^~~~~~~~~
ImportIDs was being used during construction of EmptyList, before ImportIDs itself had been constructed.