Skip to content
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

Merged
merged 1 commit into from
Nov 23, 2022

Conversation

mihaibudiu
Copy link
Contributor

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.

Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
@smolkaj
Copy link
Member

smolkaj commented Nov 23, 2022

I tried manually and can confirm that it fixes the issue.

Thanks so much Mihai for the incredibly fast diagnosis & fix!

@smolkaj
Copy link
Member

smolkaj commented Nov 23, 2022

Any ideas why https://github.com/p4lang/p4c/blob/main/testdata/p4_16_samples/pins/pins_middleblock.p4 didn't catch this, @mbudiu-vmw ?

@jafingerhut
Copy link
Contributor

@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:

cd p4c
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=DEBUG
make -j2

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.

Copy link
Contributor

@jafingerhut jafingerhut left a 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 :-)

@mihaibudiu
Copy link
Contributor Author

Uninitialized variables are not deterministic. If it happens to be 0 all works well.

@smolkaj
Copy link
Member

smolkaj commented Nov 23, 2022

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.
If we had latent undefined behavior here I suppose that's not surprising.

By the way, Mihai, props for getting your hands dirty with Bazel 👍 Thanks a lot for fixing this, once again!

Copy link
Member

@rst0git rst0git left a 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,
               ^

@mihaibudiu
Copy link
Contributor Author

@fruffy this fails with the following report: testgen-p4c-bmv2/issue3702-bmv2.p4
Is this a true positive?
Even if it is a true positive, I assume it is not really related to this PR.
If it is a true positive, can you please file a reproduction for it?
I will merge this PR anyway, since it fixes a real bug.

@mihaibudiu mihaibudiu merged commit de40246 into p4lang:main Nov 23, 2022
@mihaibudiu mihaibudiu deleted the issue3719 branch November 23, 2022 17:13
@fruffy
Copy link
Collaborator

fruffy commented Nov 23, 2022

This is an issue that has already been fixed.

@davidbolvansky
Copy link
Contributor

Uninitialized variables are not deterministic. If it happens to be 0 all works well.

If think we could enhance our Clang CI build with additional flag -ftrivial-auto-var-init=pattern - I can try.
https://clang.llvm.org/docs/ClangCommandLineReference.html

See it in action:
https://godbolt.org/z/fPMdf3Gsx

Real bugs would be more exposed now.

@apinski-cavium
Copy link

apinski-cavium commented Nov 24, 2022

If think we could enhance our Clang CI build with additional flag -ftrivial-auto-var-init=pattern - I can try.

If you are using GCC 12 or above, you can use the same option too.

@davidbolvansky
Copy link
Contributor

If think we could enhance our Clang CI build with additional flag -ftrivial-auto-var-init=pattern - I can try.

If you are using GCC 12 or above, you can use the same option too.

Yeah :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compiler Bug: nested action list?
7 participants