https://llvm.org/bugs/show_bug.cgi?id=30806
Bug ID: 30806 Summary: Wrong code generation at -O2 leading to division by zero Product: new-bugs Version: 3.9 Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: new bugs Assignee: unassignedb...@nondot.org Reporter: cl...@martinien.de CC: llvm-bugs@lists.llvm.org Classification: Unclassified Created attachment 17500 --> https://llvm.org/bugs/attachment.cgi?id=17500&action=edit Repro Attached repro causes a division by zero although it shouldn't (I tried my best to rule out undefined behavior, but if I missed something let me know). Build with build.sh and run "div_by_zero" In run.cpp "array" is only being assigned a non-NULL pointer when both a and b are both > 0: if(a > 0 && b > 0) // false at runtime! { try { array.reset(new size_t[b]()); } catch (...) { } } But later on the following code gets executed even though array.get() must return NULL: if (array.get() != 0) // Should be false at runtime; even adding "&& a > 0" here does not help { // Also this crashes: //const size_t partSize = a != 0 ? b / a : 0; const size_t partSize = b / a; // Crash here - Division by zero Side note: It works at -O1. I know that for earlier clang versions (I think 3.6) this broke even at -O1, but the workaround seen above ("Also this crashes") worked there. Best regards, Martin -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs