This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Sema] Capturing section type conflicts between #pragma clang section and section attributes
ClosedPublic

Authored by pratlucas on Apr 21 2020, 9:42 AM.

Details

Summary

Conflicting types for the same section name defined in clang section
pragmas and GNU-style section attributes were not properly captured by
Clang's Sema. The lack of diagnostics was caused by the fact the section
specification coming from attributes was handled by Sema as implicit,
even though explicitly defined by the user.

This patch enables the diagnostics for section type conflicts between
those specifications by making sure sections defined in section
attributes are correctly handled as explicit.

Diff Detail

Event Timeline

pratlucas created this revision.Apr 21 2020, 9:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 21 2020, 9:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Fixing "mising clang-format" messages.

Removing unnecessary function.

rnk added inline comments.Apr 23 2020, 10:16 AM
clang/include/clang/AST/ASTContext.h
2978

It seems like there is no need for this to be defined inline, since it is presumably cold code.

clang/test/Sema/pragma-clang-section.c
28

Please add a case like:

const int y __attribute__((section("myrodata.6"))) = 11;

There should be no diagnostics in this case, and I expect myrodata.6 to override the pragma, since it is more specific to the declaration.

pratlucas updated this revision to Diff 260630.Apr 28 2020, 7:20 AM

Updateing test.

pratlucas marked 4 inline comments as done.Apr 28 2020, 7:24 AM
pratlucas added inline comments.
clang/include/clang/AST/ASTContext.h
2978

The inline's purpose here is just to allow the definition in the header file, avoiding multiple definition errors.

clang/test/Sema/pragma-clang-section.c
28

I've added this case to the test.
The overriding behaviour is already checked by clang/test/CodeGen/clang-sections-attribute.c.

pratlucas marked 2 inline comments as done.Apr 28 2020, 7:24 AM
rnk accepted this revision.May 5 2020, 4:01 PM

lgtm

clang/include/clang/AST/ASTContext.h
2978

Yes, I am suggesting that the body be moved out of line, but this is optional. Less code in headers --> faster builds.

This revision is now accepted and ready to land.May 5 2020, 4:01 PM
pratlucas updated this revision to Diff 262594.May 7 2020, 3:48 AM

Addressing review comment.

pratlucas marked an inline comment as done.May 7 2020, 3:49 AM
This revision was automatically updated to reflect the committed changes.