Skip to content

Constraints on declaration after definition of same function are lost #399

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

Closed
mattmccutchen-cci opened this issue Jan 25, 2021 · 0 comments
Labels

Comments

@mattmccutchen-cci
Copy link
Member

When a declaration of a function comes after a definition of the same function, any constraints placed on the declaration are lost. This seems to be due to an asymmetry in the declaration merging code.

Example:

defn_then_decl.c:

void foo(int *p) {}

#define MYDECL void foo(int *p);

MYDECL

3c -output-postfix=checked defn_then_decl.c writes the following to defn_then_decl.checked.c:

void foo(_Ptr<int> p) {}

#define MYDECL void foo(int *p);

MYDECL

Then clang defn_then_decl.checked.c fails with:

defn_then_decl.checked.c:5:1: error: conflicting types for 'foo'
MYDECL
^
defn_then_decl.checked.c:3:21: note: expanded from macro 'MYDECL'
#define MYDECL void foo(int *p);
                    ^
defn_then_decl.checked.c:1:6: note: previous definition is here
void foo(_Ptr<int> p) {}
     ^
1 error generated.

Compare to decl_then_defn.c:

#define MYDECL void foo(int *p);

MYDECL

void foo(int *p) {}

3C correctly does not change this because of the macro.

@john-h-kastner expressed interest in fixing this if it ends up being a small amount of work.

john-h-kastner added a commit that referenced this issue Feb 1, 2021
Ensure that constrains generated due to a function's declaration are
applied to the variables generated at the definition even when
declaration appears after the definition.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant