Bug 11471 – [profile+nothrow] `asm` statements rejected in `nothrow` functions if built with "-profile"

Status
RESOLVED
Resolution
WORKSFORME
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-07T12:13:00Z
Last change time
2014-06-29T07:53:11Z
Keywords
pull, rejects-valid
Assigned to
code
Creator
verylonglogin.reg
Depends on
12979

Comments

Comment #0 by verylonglogin.reg — 2013-11-07T12:13:53Z
Error iff built with "-profile": --- void main() nothrow { asm { nop; } } // Error: asm statements are assumed to throw --- Documentation doesn't say `asm` can't be used in `nothrow` functions and IMO such restriction looks too strong. As a result some druntime (Issue 10260) and Phobos (Issue 10849) parts can't be used while profiling. Let it be a "rejects-valid" bug for now.
Comment #1 by verylonglogin.reg — 2013-11-07T12:14:41Z
*** Issue 10260 has been marked as a duplicate of this issue. ***
Comment #2 by verylonglogin.reg — 2013-11-07T12:15:26Z
*** Issue 10849 has been marked as a duplicate of this issue. ***
Comment #3 by dlang-bugzilla — 2014-03-27T17:48:54Z
Comment #4 by yebblies — 2014-06-08T05:18:55Z
This really should be generating the same error with and without profile. I have no idea why it doesn't. For some reason the function's type is not marked as nothrow until _after_ the first time blockExit is run on it.
Comment #5 by blah38621 — 2014-06-08T17:59:19Z
I would agree that assuming asm statements always throw is not exactly useful, especially as the inline asm statements are there for performance. Is there some way that either the compiler could check to see if the asm actually throws, or else for the user to tell the compiler that an ASM statement doesn't throw?
Comment #6 by k.hara.pg — 2014-06-20T16:59:24Z
The root issue is in FuncDeclaration::semantic3. ... else if (hasReturnExp & 8) // if inline asm { flags &= ~FUNCFLAGnothrowInprocess; } else { // Check for errors related to 'nothrow'. unsigned int nothrowErrors = global.errors; int blockexit = fbody->blockExit(this, f->isnothrow); if (f->isnothrow && (global.errors != nothrowErrors) ) ::error(loc, "%s '%s' is nothrow yet may throw", kind(), toPrettyChars()); ... In front-end, if a function body has inline asm statements, the function's nothrow check is skipped! But many functions in druntime rely on the loose behavior currently.
Comment #7 by k.hara.pg — 2014-06-29T07:06:36Z
Comment #8 by github-bugzilla — 2014-06-29T07:51:00Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/31b5a22bfb5415ecd953e90fad967a537c27bd53 fix Issue 11471 - [profile+nothrow] `asm` statements rejected in `nothrow` functions if built with "-profile" Workaround fix is introduced in e6c308938d02d1cbfc57c37c03d06bff0ec00c74, so just add a test case. https://github.com/D-Programming-Language/dmd/commit/968566c3620707480a77c38a17d5d8317a0ff4f7 Merge pull request #3702 from 9rnsr/fix11471 [REG2.066a] Issue 11471 - [profile+nothrow] `asm` statements rejected in `nothrow` functions if built with "-profile"