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

cabs2cil: don't let extern inline prototypes replace definitions of… #25

Closed
wants to merge 15 commits into from

Conversation

stephenrkell
Copy link
Contributor

…the same function seen earlier.

Currently, if a .c file defines an extern inline function and then repeats its prototype without a definition, the definition is omitted from the .cil.c output file. This tiny patch fixes that bug.

@kerneis
Copy link
Contributor

kerneis commented Mar 30, 2016

Can you please add a test? If you are lost in CIL's test infrastructure, please just give a minimal C program that would compile (and/or run) with your patch, but not without.

@kerneis
Copy link
Contributor

kerneis commented Mar 30, 2016

Ah, looks like you already did that (a long time ago) in issue #14. I'll try to re-use your program from there (but it will likely be faster if you update this PR with it). Thanks a lot for the patch anyway :-)

Previously CIL's handling of gcc's alias attribute was broken. It would
create a new function, rather than a linker alias, and would not work
for varargs functions or any kind of variable. This patch removes that
code in favour of a "do nothing" implementation which correctly passes
the simple test case provided.
When a static local is promoted to a global, the alpha renaming usually
remembers any suffix added and chooses a fresh suffix for later vars of
the same name. However, if the same function also has a (non-static)
local with the same name, this gets clobbered: the alpha renamer throws
away the renaming state after the function scope is done. This can be
triggered if (among other cases) two functions in the same file both
have like-named statics hiding other locals/formals (seen in Motif).
@stephenrkell
Copy link
Contributor Author

Once again my git skills have let me down... I've pushed a new commit to my fork, adding the test case that you (very reasonably) asked for. I've also pushed two unrelated commits that belong in separate pull requests. I've no idea how to exclude those two from this pull request... maybe you can cherry-pick?

@kerneis
Copy link
Contributor

kerneis commented Apr 7, 2016 via email

…stdin and stdout.

Previously single-character output filenames, including "-" for stdout,
were being substituted with generated names. Among other things, this
broke the assemble-to-stdout pattern used in some configure scripts.
Similarly, single-character input filenames were not properly supported.
We make the following small changes and also add a test case.

Make cilly accept input on stdin, and understand gcc's "-x <lang>" option

OutputFile.pm: prevent output filenames that begin with a hyphen from being confused with command-line switches.

Cilly.pm.in: be consistent about using stderr for diagnostic and debug output.

main.ml: permit '-' as an input file argument on the command line.

OutputFile.pm: permit '-' as an output filename, denoting stdout... meaning we must neither rewrite it to './-' nor do the protect check on it.

Add a test case for input and output filenames of '-'.
Previously, if the user defined a function, say strstr(), which also has
a builtin version, __builtin_strstr(), but the file contained calls only
to the builtin version, the user's version would be ignored. This is a
divergence from gcc's behaviour, where the user's function would be
called instead of the builtin (even for calls directly to the builtin).
The divergence is caused by CIL deleting the apparently unused user
function. Fix it by marking the user-defined function as referenced
whenever the builtin is marked.
Previously CIL was incapable of faithfully preserving inline semantics
in all cases, because it lost information when merging declarations and
definitions into a single varinfo. We now remember all that information,
and ensure when printing that we generate adequate prototypes to
represent the distinct cases under both C99's rules and GNU C's rules
governing "inline" and "extern inline".
Previously the parser would reject extended-form inline assembly
statements with clobber list entries consisting of multiple implicitly
concatenated string literals. This caused parse errors in some code,
such as in ffmpeg, that uses heavily macroized inline assembly.
@stephenrkell
Copy link
Contributor Author

I'm closing this since I have recently added a bunch more changes on my fork. They are all ready for pulling, but I'll request them one-by-one, rather than this request which is about pulling my whole develop/ branch in one go.

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.

2 participants