-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Simple program goes into infinite loop #796
Comments
What makes you think this is a glog issue? The loop contains undefined behavior so it could be the compiler could be doing something weird with the loop as a result, perhaps assuming that i==0.
I can reproduce the issue with the undefined behavior, but if I avoid it by using |
The signed integer overflow also caught my eye. Ignoring warnings is generally a bad idea. |
Remove the LOG(ERROR) statement, the loop ends. I don't know whether it's a glog issue and I lean toward gcc issue. But so far the LOG(ERROR) is the only way I find to invoke the issue.
How did you get this? My bazel build only gave one warning of unused variable (bazel version and gcc version pasted in the first comment).
This is just an oversimplified example to demonstrate the unexpected behavior. The issue originated from a much complicated logic where no easy target as this dumb statement. Anyway, I changed the program a bit to get rid of the unused variable. Now there are just two LOG statements in the body.
|
The posted program didn't actually produce the warning. Please give it a try. |
You can see a similar case here where undefined behavior leads to an infinite loop, whether or not the compiler is clever enough to print a warning: https://community.st.com/s/question/0D50X0000C6bXXMSQ2/solved-infinite-loop-without-warning-iteration-n-invokes-undefined-behavior-using-pointers-to-get-data-from-a-function |
Thanks Rodrigo. Suppose As said I lean toward this is more of a compiler issue and I'll ask on gcc community. It will be more convincible If I could get a more language native way to demonstrate the issue without touching glog. |
This is a reasonable expectation but unfortunately wrong. Since the behavior of In this case, I would guess the compiler sees that If you're not sure what caused this in your original code, you could look into using ubsan to try to catch it. I'll close this as I doubt it's specific to glog, although if you're able to reproduce the issue without undefined behavior in the loop please let us know. |
Thanks Rodrigo. Your explanation makes total sense. Special thanks for correcting my understanding on undefined behavior! |
The following program prints the message infinitely times, under the opt mode.
Sample output:
BUILD file:
uname -a: Linux 276db1447620 5.14.16-1rodete1-amd64 #1 SMP Debian 5.14.16-1rodete1 (2021-11-17) x86_64 GNU/Linux
Bazel version: 5.0.0
gcc version: gcc version 8.3.0 (Debian 8.3.0-6)
Bazel workspace:
Docker file if helpful:
The text was updated successfully, but these errors were encountered: