This is an archive of the discontinued LLVM Phabricator instance.

[Sema] PR23090 Crash when return type or parameter types for extern "C" functions don't have external linkage
AbandonedPublic

Authored by hintonda on Feb 17 2016, 5:57 PM.

Details

Reviewers
None
Summary

Added checks to make sure the return type and parameter types for functions
declared as extern "C" have external linkage.

Diff Detail

Event Timeline

hintonda updated this revision to Diff 48267.Feb 17 2016, 5:57 PM
hintonda retitled this revision from to [Sema] PR23090 Crash when return type or parameter types for extern "C" functions don't have external linkage.
hintonda updated this object.
hintonda added reviewers: majnemer, rsmith.
hintonda added a subscriber: cfe-commits.

Here's an example of when this will cause a crash:

namespace {
Struct G;
extern "C" G *f(); has external linkage
G *f();
will assert since it has internal linkage because of G and doesn't match previous declaration
}

This also causes a few other test failures (~8) which will need to be fixed if this patch is accepted.

This change breaks a couple tests in test/SemaCXX/linkage.cpp where we no longer allow mixing internal and external linkage, i.e., extern "C" functions have external linkage no matter where they are declared, but return types and parameters declared in anonymous namespaces have internal linkage.

Not yet sure how to go about fixing those, but one was based on PR9316, however, the test is more complicated and is invalid -- so we don't generate code.

hintonda updated this revision to Diff 48601.Feb 20 2016, 2:39 PM

Fixed additional tests.

hintonda updated this revision to Diff 48617.Feb 21 2016, 6:11 AM
  • Fix remaining test failures caused by linkage errors.
rsmith requested changes to this revision.Apr 7 2016, 11:49 AM
rsmith edited edge metadata.

Why do you think this is ill-formed? Using a type with internal linkage as the type of an extern "C" function is explicitly permitted by the C++ standard. [basic.link]p8 says:

"A type without linkage shall not be used as the type of a variable or function with external linkage unless the entity has C language linkage [...]."

This revision now requires changes to proceed.Apr 7 2016, 11:49 AM
hintonda removed a subscriber: cfe-commits.
hintonda abandoned this revision.Jul 18 2017, 1:15 PM