On Thu, Oct 09, 2025 at 08:50:30PM -0700, Leo Yin wrote:
> I changed compiler option -O2 in pet/Makefile to -O0 and build PPCG. When
> run ppcg with the following simple case, it coredumped.
Thanks for the report. It seems I didn't handle the return value
of getFileRef correctly, but this got masked when compiling with
optimizations.
This should fix it:
diff --git a/pet.cc b/pet.cc
index 1970777..b157861 100644
--- a/pet.cc
+++ b/pet.cc
@@ -1111,22 +1111,15 @@ struct HasGetFileRef<T, ::void_t<decltype(&T::getFileRef)>> :
template <typename T,
typename std::enable_if<HasGetFileRef<T>::value, bool>::type = true>
static auto getFile(T& obj, const std::string &filename)
- -> llvm::ErrorOr<decltype(*obj.getFileRef(filename))>
{
- auto file = obj.getFileRef(filename);
- if (!file)
- return std::error_code();
- return *file;
+ return obj.getFileRef(filename);
}
template <typename T,
typename std::enable_if<!HasGetFileRef<T>::value, bool>::type = true>
static llvm::ErrorOr<const FileEntry *> getFile(T& obj,
const std::string &filename)
{
- const FileEntry *file = ignore_error(obj.getFile(filename));
- if (!file)
- return std::error_code();
- return file;
+ return ignore_error(obj.getFile(filename));
}
/* Return the ownership of "buffer".
I'll clean it up and do some further testing later this week.
The other issue will have to wait a bit.
skimo