-
Notifications
You must be signed in to change notification settings - Fork 449
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
Fix bug caused by uninitialized variable in typechecker #3720
Conversation
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
837cfa6
to
0ecbda1
Compare
I tried manually and can confirm that it fixes the issue. Thanks so much Mihai for the incredibly fast diagnosis & fix! |
Any ideas why https://github.com/p4lang/p4c/blob/main/testdata/p4_16_samples/pins/pins_middleblock.p4 didn't catch this, @mbudiu-vmw ? |
@smolkaj I do not know why your tests were failing, but when I built with latest p4c source code, without the changes in this PR, using the following commands on an Ubuntu 20.04 system:
I got no errors or crashes at all when compiling the version of pins_middleblock.p4 that is in the p4c repo today, nor when attempting to compile the version of middleblock.p4 in this repo: https://github.com/p4lang/p4c/blob/main/testdata/p4_16_samples/pins/pins_middleblock.p4 I don't know why you did, but we could have been using different versions of OS, glibc, C++ compiler, etc. as I mentioned above. I can give you the versions I ran with, if it is of interest to you, but I don't know how else to explain it than whatever is different about our build and/or run-time environments. |
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.
I can approve of this if you want, Mihai, but I don't know the code, so not sure why you would ask me for review unless it is that I respond relatively quickly :-)
Uninitialized variables are not deterministic. If it happens to be 0 all works well. |
Makes sense (well, sort of, but this is C++ after all) :) Andy, on the other thread we discussed that both Mihai and I were able to reproduce with Bazel, but not with cmake. By the way, Mihai, props for getting your hands dirty with Bazel 👍 Thanks a lot for fixing this, once again! |
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
cppcheck is also able to detect this problem:
$ cppcheck frontends/p4/typeChecking/typeChecker.cpp --inconclusive --enable=warning
Checking frontends/p4/typeChecking/typeChecker.cpp ...
frontends/p4/typeChecking/typeChecker.cpp:131:16: warning: Member variable 'TypeInference::currentActionList' is not initialized in the constructor. [uninitMemberVar]
TypeInference::TypeInference(ReferenceMap* refMap, TypeMap* typeMap, bool readOnly,
^
@fruffy this fails with the following report: |
This is an issue that has already been fixed. |
If think we could enhance our Clang CI build with additional flag -ftrivial-auto-var-init=pattern - I can try. See it in action: Real bugs would be more exposed now. |
If you are using GCC 12 or above, you can use the same option too. |
Yeah :) |
Signed-off-by: Mihai Budiu mbudiu@vmware.com
Fixes #3719
Also fixed a couple of warnings in gc.cpp
There is no simple test, but hopefully @smolkaj can confirm that the bug is fixed.