Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 12979 - Nothrow violation error is hidden by inline assembler #4033

Merged
merged 2 commits into from Oct 6, 2014

Conversation

MartinNowak
Copy link
Member

  • deprecate using unattributed asm in attributed functions

  • add explicit attributes on asm statments (unverified by compiler)

    asm pure nothrow @nogc @trusted {
    //...
    }

  • added new CompoundAsmStatement because the parser
    already splits asm blocks into many AsmStatements

@MartinNowak
Copy link
Member Author

This triggers many warnings in druntime about missing returns, which probably happens because of the added blockExit check, so I'll have to revise the pull.

@WalterBright
Copy link
Member

Adding new grammar will also require documentation pulls.

@ibuclaw
Copy link
Member

ibuclaw commented Sep 29, 2014

cool


void foo()
{
asm @trusted pure nothrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the language consistency, I think we should also support @trusted, @nogc and pure attributes on iasm statement, and we need to change a bare iasm as impure, unsafe, gc-able, and throwable by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too.

@MartinNowak
Copy link
Member Author

There is also a grammar pull dlang/dlang.org#667.

@MartinNowak MartinNowak changed the title fix Issue 12979 - Nothrow violation error is hidden by inline assembler parse postfix attributes on asm blocks Sep 29, 2014
@MartinNowak
Copy link
Member Author

Requires dlang/druntime#974 first.

@WalterBright
Copy link
Member

How can this be marked as [enhancement] in the PR list?

@yebblies
Copy link
Member

How can this be marked as [enhancement] in the PR list?

  1. On this page, go to the top-right corner, just to the right of the PR description, and click "Labels" then click "Enhancement".
  2. On the pulls page check the box next to this pull then select the "Label" dropdown and click "Enhancement".

@WalterBright
Copy link
Member

Thanks, @yebblies, though could someone else please do this as github doesn't like my laptop.

@9rnsr
Copy link
Contributor

9rnsr commented Sep 30, 2014

This enhancement will fill the semantic gap between inline assembler and function attributes.

@9rnsr
Copy link
Contributor

9rnsr commented Sep 30, 2014

Looks good.

@@ -747,6 +747,20 @@ class AsmStatement : public Statement
void accept(Visitor *v) { v->visit(this); }
};

// a complete asm {} block
class AsmCompoundStatement : public CompoundStatement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In dmd code CompoundDeclarationStatement already exists, so the name CompoundAsmStatement might be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually thinking about AsmStatement and renaming the old AsmStatement to AsmInstruction. That would be far less confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because AsmStatement::semantic splits them up into one-per-instruction blocks right? Can't we just defer that split to the glue layer somehow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I should probably rename GDC's as ExtAsmTemplate. ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because AsmStatement::semantic splits them up into one-per-instruction blocks right?

The parser already does that. I think the main reason for this are LabelStatements which can be accessed from outside asm blocks.

Can't we just defer that split to the glue layer somehow?

Maybe, but this isn't part of this pull request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but this isn't part of this pull request.

Fair enough.

@MartinNowak MartinNowak changed the title parse postfix attributes on asm blocks fix Issue 12979 - Nothrow violation error is hidden by inline assembler Sep 30, 2014
@9rnsr
Copy link
Contributor

9rnsr commented Oct 2, 2014

@MartinNowak Druntime PR was merged, so this PR should be ready to merge.
But, auto-tester shows an error in fail_compilation/deprecate12979a.d. Let's fix it.

If others have no complaint about this enhancement, I'll merge this in this weekend (UTC 10/5 0:00).

@MartinNowak
Copy link
Member Author

But, auto-tester shows an error in fail_compilation/deprecate12979a.d.

done

- deprecate using unattributed asm in attributed functions

- add explicit attributes on asm statments (unverified by compiler)

  asm pure nothrow @nogc @trusted {
    //...
  }

- added new CompoundAsmStatement because the parser
  already splits asm blocks into many AsmStatements
if (mustNotThrow)
s->error("asm statements are assumed to throw", s->toChars());
if (mustNotThrow && !(s->stc & STCnothrow))
s->deprecation("asm block is not nothrow");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asm statement, not asm block, as we should consistently refer to things with the same phrase. I also don't like the double negative, and would prefer something along the lines of:

asm statement is assumed to throw - mark it with 'nothrow' attribute if it does not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asm statement, not asm block, as we should consistently refer to things with the same phrase.

I mixed up the wording because AsmStatement in the compiler is actually a single asm instruction.

@9rnsr
Copy link
Contributor

9rnsr commented Oct 5, 2014

@WalterBright You would have no objection about the enhancement feature itself, right?.

@MartinNowak I'll defer the merging until your reaction comes back.

@MartinNowak
Copy link
Member Author

Updated the wording of the error messages.

@dnadlinger
Copy link
Member

@redstar, @AlexeyProkhin: When this is in, we can probably get rid of our AsmBlockStatement (LDC keeps asm blocks as one for different reasons).

@9rnsr
Copy link
Contributor

9rnsr commented Oct 6, 2014

LGTM.

@9rnsr
Copy link
Contributor

9rnsr commented Oct 6, 2014

Auto-merge toggled on

9rnsr added a commit that referenced this pull request Oct 6, 2014
fix Issue 12979 - Nothrow violation error is hidden by inline assembler
@9rnsr 9rnsr merged commit a1ec5c7 into dlang:master Oct 6, 2014
@MartinNowak MartinNowak deleted the fix12979 branch October 6, 2014 17:46
@9rnsr
Copy link
Contributor

9rnsr commented Oct 8, 2014

From a practical reason, I'd propose an additional enhancement https://issues.dlang.org/show_bug.cgi?id=13589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants