This is an archive of the discontinued LLVM Phabricator instance.

Keep invalid function body as part of the AST
AbandonedPublic

Authored by ogoffart on Apr 20 2016, 8:38 AM.

Details

Summary
struct XX {
 double foo(invalid_type xx);
};
double XX::foo(invalid_type xx)
{ 
 return 45; 
}

We should keep XX::foo and its function body as part of the AST so tools can still do something with the body even if the definition is wrong.
Inline function would already be kept, but not when they are redeclarations.

Diff Detail

Event Timeline

ogoffart updated this revision to Diff 54377.Apr 20 2016, 8:38 AM
ogoffart retitled this revision from to Keep invalid function body as part of the AST.
ogoffart updated this object.
ogoffart added reviewers: cfe-commits, rsmith.
kfunk added a subscriber: kfunk.Apr 20 2016, 11:50 AM
ogoffart updated this object.Apr 22 2016, 1:26 AM
rsmith added inline comments.Apr 26 2016, 5:32 PM
lib/Sema/SemaDecl.cpp
5044–5045

Can we delete the invalid-decl check entirely here? If it's doing something important, we need to figure out what and make sure we preserve that intent if it's important, but either way it doesn't make a lot of sense to me for this to depend on whether the declaration has a definition.

ogoffart added inline comments.Apr 27 2016, 12:45 AM
lib/Sema/SemaDecl.cpp
5044–5045

I tried that, but then we have a failure in Sema/function-redecl.c and Sema/predefined-function.c

int eli(float b); // expected-note {{previous declaration is here}} \
int foo() {
  int eli(int (int)); // expected-error {{conflicting types for 'eli'}}
  eli(b); // expected-error{{passing 'int (int)' to parameter of incompatible type 'float'}}
   return 0;
 }

If we keep the invalid declaration, there would not be an error in the call to eli(b)

But is that a behaviour we would change?

An alternative patch is uploaded there: http://reviews.llvm.org/D19764

Is this better than the alternative http://reviews.llvm.org/D19764 ?