This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Prohibit function-scope compound literals with address spaces.
ClosedPublic

Authored by ebevhan on Aug 29 2018, 7:27 AM.

Details

Reviewers
efriedma
rjmccall
Summary

In C, compound literals in function scope are lvalues with
automatic storage duration. This means that generally, they
cannot be address space-qualified since you cannot have
address space-qualified objects with automatic storage duration.

The Embedded-C specification also adds a clause to the section
on compound literals that prohibits this.

We might want to check the 'alloca address space' here, but
neither ASTContext nor TargetInfo seem to have this.

Diff Detail

Event Timeline

ebevhan created this revision.Aug 29 2018, 7:27 AM
rjmccall accepted this revision.Aug 29 2018, 9:50 AM

LGTM, with one minor suggestion.

lib/Sema/SemaExpr.cpp
5745

Usually when we mention a standard section like this, it's a prelude to a quote. If you're just paraphrasing, I think we can trust people to find the right standard section.

This revision is now accepted and ready to land.Aug 29 2018, 9:50 AM
ebevhan added inline comments.Aug 29 2018, 11:59 PM
lib/Sema/SemaExpr.cpp
5745

Hm, alright. I figured it was better to both provide the exact section and also include a summary here so you don't have to look it up.

Should I change it or is it good anyway?

rjmccall added inline comments.Aug 30 2018, 1:14 AM
lib/Sema/SemaExpr.cpp
5745

It's fine to include a reference to the standard. The way you've done it here makes it look like a quote at first glance, which it isn't. You should just say "See C99 6.5.2.5p6" if you think that's an important citation to make.

In this case, though, I don't think it's a particularly valuable citation. Remember that this code is in the middle of a function dedicated to the rules of section 6.5.2.5, so unless you're actually quoting the text because there's some important subtlety, I think you can assume general familiarity (and/or that the reader has the standard open). There *is* a better citation, though: the Embedded C spec explicitly says:

If the compound literal occurs inside the body of a function, the type name shall not be qualified by an address-space qualifier.

I'd cite it with a title like "Embedded C modifications to C99 6.5.2.5".

By the way, LLVM code style leaves a space between if and the opening parenthesis of the condition.

ebevhan updated this revision to Diff 163277.Aug 30 2018, 1:40 AM
ebevhan edited the summary of this revision. (Show Details)

Added Embedded-C clause quote.
Fixed formatting.

rjmccall accepted this revision.Aug 30 2018, 1:52 AM

LGTM.

Thanks!

I don't have commit access, so it would be appreciated if someone could commit it.

rjmccall closed this revision.Sep 5 2018, 12:24 PM

Committed as r341491.