This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Address review comments on r352930
ClosedPublic

Authored by sunfish on Mar 18 2019, 4:07 PM.

Details

Summary

This patch addresses the review comments on r352930:

  • Removes redundant diagnostic checking code
  • Removes errnoneous use of diag::err_alias_is_definition, which turned out to be ineffective anyway since functions can be defined later in the translation unit and avoid detection.
  • Adds a test for various invalid cases for import_name and import_module.

Diff Detail

Event Timeline

sunfish created this revision.Mar 18 2019, 4:07 PM

I love functional changes that remove code and add tests -- thank you for these!

Removes errnoneous use of diag::err_alias_is_definition, which turned out to be ineffective anyway since functions can be defined later in the translation unit and avoid detection.

If you need to keep the prohibition that these attributes not be applied to functions with definitions, there are ways to accomplish that (we merge declarations and can decide what to do at that point if we see a declaration that is a definition). Given that, do you still want to lift this restriction?

test/Sema/attr-wasm.c
3 ↗(On Diff #191200)

Was this intended to be used somewhere? Probably can just be removed if not.

15 ↗(On Diff #191200)

Same here.

Removes errnoneous use of diag::err_alias_is_definition, which turned out to be ineffective anyway since functions can be defined later in the translation unit and avoid detection.

If you need to keep the prohibition that these attributes not be applied to functions with definitions, there are ways to accomplish that (we merge declarations and can decide what to do at that point if we see a declaration that is a definition). Given that, do you still want to lift this restriction?

These attributes don't make sense on definitions. So right now, they are silently ignored when applied to definitions. That's effectively the current behavior too, because the existing check doesn't work as intended, so the change here doesn't change anything in practice yet.

A diagnostic would be slightly tidier, but I'm not familiar enough with clang to do this quickly and didn't want to delay the rest of the patch while I investigated. Do you know the specific places we'd need to change to diagnose this?

sunfish marked an inline comment as done.Mar 19 2019, 5:19 PM
sunfish added inline comments.
test/Sema/attr-wasm.c
3 ↗(On Diff #191200)

No, you're right that we don't need this (it's copypasta from another test). I'll remove it from the patch.

Removes errnoneous use of diag::err_alias_is_definition, which turned out to be ineffective anyway since functions can be defined later in the translation unit and avoid detection.

If you need to keep the prohibition that these attributes not be applied to functions with definitions, there are ways to accomplish that (we merge declarations and can decide what to do at that point if we see a declaration that is a definition). Given that, do you still want to lift this restriction?

These attributes don't make sense on definitions. So right now, they are silently ignored when applied to definitions. That's effectively the current behavior too, because the existing check doesn't work as intended, so the change here doesn't change anything in practice yet.

A diagnostic would be slightly tidier, but I'm not familiar enough with clang to do this quickly and didn't want to delay the rest of the patch while I investigated. Do you know the specific places we'd need to change to diagnose this?

I'd be fine addressing it in a follow-up patch, but silently ignoring attributes is something I consider a bug. Users have a *very* difficult time seeing the difference between "accepted and doing its thing" and "silently ignored" depending on the attribute semantics, so that's why we explicitly tell them when we're ignoring an attribute.

As for where to handle this, I'd follow our typical "merge" pattern for attributes. 1) Add Sema::mergeImportNameAttr() that does all your error checking for definitions and creates an attribute if there's no issues, 2) From handleImportNameAttr(), handle your typical semantic checks and then calls S.mergeImportNameAttr() to try to create the attribute, and if it is created, attach it to the declaration, 3) hook the new merge operation up in mergeDeclAttribute() in SemaDecl.cpp.

If you don't address it as part of this patch, can you add a bug to bugzilla so that we get this tracked (if you don't plan to fix the issue soon) and add a test case to this patch demonstrating that we are silently ignoring the attribute with a FIXME comment?

sunfish updated this revision to Diff 197215.Apr 29 2019, 4:15 PM

Implemented proper diagnostics for import_name/import_module on functions with definitions, and updated the test.

I'm unsure of the DIAG_SIZE_SEMA change, but without it, the build fails with this error:

/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp:72:3: error: static assertion failed: DIAG_SIZE_SEMA is insufficient to contain all diagnostics, it may need to be made larger in DiagnosticIDs.h.
   static_assert(                                                               \
   ^
/llvm/tools/clang/lib/Basic/DiagnosticIDs.cpp:88:1: note: in expansion of macro ‘VALIDATE_DIAG_SIZE’
 VALIDATE_DIAG_SIZE(SEMA)
 ^~~~~~~~~~~~~~~~~~
aaron.ballman added inline comments.May 1 2019, 5:49 AM
include/clang/Basic/DiagnosticIDs.h
39 ↗(On Diff #197215)

I think this should be a separate commit, and I'd recommend updating it to 4000 to give ourselves more wiggle room.

include/clang/Basic/DiagnosticSemaKinds.td
9649–9656 ↗(On Diff #197215)

How about: "import %select{module|name}0 does not match previous declaration" and "import %select{module|name}0 cannot be applied to a function with a definition"?

include/clang/Sema/Sema.h
2616–2621 ↗(On Diff #197215)

I'd rather see the typical pattern used here: one taking a ParsedAttr and the other taking a semantic attribute.

lib/Sema/SemaDeclAttr.cpp
5764–5765 ↗(On Diff #197215)

const auto *

5769 ↗(On Diff #197215)

I don't see anything testing this note or the preceding warning, can you add some tests that exercise it?

5773 ↗(On Diff #197215)

I don't see any tests for this either.

5781–5783 ↗(On Diff #197215)

I wonder if we want to generalize this with a template (for the attribute type) if we could generalize the diagnostic text a bit more (or add an additional parameter for it)?

5786–5787 ↗(On Diff #197215)

const auto *

5790–5791 ↗(On Diff #197215)

Missing tests.

5795 ↗(On Diff #197215)

Missing tests.

sunfish marked 10 inline comments as done.Dec 21 2019, 12:03 AM

I apologize for the extraordinary delays here; at long last, I've now addressed your feedback.

lib/Sema/SemaDeclAttr.cpp
5781–5783 ↗(On Diff #197215)

The diagnostic name is now generalized, but it seems awkward to pass around the numbers to pick which variant of the string to use, so I didn't implement this yet.

sunfish updated this revision to Diff 235005.Dec 21 2019, 12:05 AM

Address review feedback.

aaron.ballman added inline comments.Dec 24 2019, 10:28 AM
clang/lib/Sema/SemaDecl.cpp
2601–2604

You should probably have some tests for the redeclaration behavior somewhere. The way you usually do this is to declare the function with the attribute, then declare the function again without the attribute but see that it is in fact inherited. We sometimes use AST dumping tests for this.

clang/test/Sema/attr-wasm.c
12

Are you intending to fix this as part of the patch?

16

Uncertain how important you think this may be: should we include the import names in this diagnostic? e.g., import name (%0) does not match the import name (%1) of the previous declaration or somesuch? I don't know how often users will hide these attributes behind macros, which is the case I was worried might be confusing.

26

Same question about this FIXME.

sunfish updated this revision to Diff 268329.Jun 3 2020, 4:21 PM
  • Add tests for redeclaration behavior
  • Remove disabled tests (previously marked with FIXMEs)
  • Made the mismatch warning more informative.
sunfish marked 3 inline comments as done.Jun 3 2020, 4:31 PM

I apologize again for the major delay. I've now updated the patch and addressed all of your comments.

clang/lib/Sema/SemaDecl.cpp
2601–2604

I've now added tests for this as you suggested.

clang/test/Sema/attr-wasm.c
12

I've made a few attempts at fixing this, but I'm not very familiar with these parts of clang, and I've been unable to find another attribute with a similar diagnostic.

The weak_import attribute seems like it should be one, with its warn_attribute_invalid_on_definition warning, and there's code in clang to issue that warning for both functions and variables, however the function version of the diagnostic doesn't seem to work, and only the variable version has tests.

So for now I've just removed these tests, to at least unblock the rest of this patch. If anyone knows how to implement these diagnostics, I'd be interested.

16

I've now updated the patch to provide a more informative message, following your suggestion here.

aaron.ballman accepted this revision.Jun 5 2020, 6:53 AM

LGTM, thank you!

This revision is now accepted and ready to land.Jun 5 2020, 6:53 AM
thakis added a subscriber: thakis.Jun 5 2020, 11:44 AM

This breaks check-clang everywhere, e.g. here http://lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/39534/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Awarning-flags.c

Please take a look and revert if it takes a while to fix.

Going forward, please run check-clang before landing clang changes, or look at the permerge bot output which predicted this failure (https://reviews.llvm.org/B59001)

This revision was automatically updated to reflect the committed changes.