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

Add attribute [[noreturn]] (C++11) to functions that will not return #10843

Merged
merged 1 commit into from Aug 22, 2017

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Jul 16, 2017

Add attribute [[noreturn]] (C++11) to functions that will not return.

Rationale:

  • Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  • Potentially enable additional compiler optimizations

src/random.cpp Outdated
@@ -39,7 +39,7 @@
#include <openssl/err.h>
#include <openssl/rand.h>

static void RandFailure()
[[noreturn]] static void RandFailure()
{
LogPrintf("Failed to read randomness, aborting\n");
abort();
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change this to std::abort() so that its clearer that we're really [[noreturn]]ing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! Fixed! :-)

@sipa
Copy link
Member

sipa commented Jul 16, 2017

utACK 2e737cf996336fbf74ceb56d3f105fd7fcc13a3b

Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

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

utACK

@paveljanik
Copy link
Contributor

ACK 2e737cf

@laanwj
Copy link
Member

laanwj commented Jul 17, 2017

The PR description mention 'functions' where this changes only one function. Is that intentional, or did you miss something while pushing?

@gmaxwell
Copy link
Contributor

There were more before...

@practicalswift
Copy link
Contributor Author

@laanwj Yes, originally I aimed to add the [[noreturn]] attribute also to:

  • BitcoinApplication::handleRunawayException(const QString &message) (in qt/bitcoin.cpp)
  • Shutdown()/StartShutdown() (in test/test_bitcoin_main.cpp)

But I ran into some compilation issues that I didn't have time to follow up on, so I excluded them from this PR.

@@ -519,7 +519,7 @@ void BitcoinApplication::shutdownResult()
quit(); // Exit main loop after shutdown finished
}

void BitcoinApplication::handleRunawayException(const QString &message)
[[noreturn]] void BitcoinApplication::handleRunawayException(const QString &message)
{
QMessageBox::critical(0, "Runaway exception", BitcoinGUI::tr("A fatal error occurred. Bitcoin can no longer continue safely and will quit.") + QString("\n\n") + message);
::exit(EXIT_FAILURE);
Copy link
Contributor

Choose a reason for hiding this comment

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

std::exit?

Rationale:
* Reduce the number of false positives from static analyzers
* Potentially enable additional compiler optimizations
@practicalswift
Copy link
Contributor Author

I've now added the [[noreturn]] attribute to Shutdown()/StartShutdown() (in test/test_bitcoin_main.cpp).

However, after some digging it appears that [[noreturn]] might not be correct for BitcoinApplication::handleRunawayException(const QString &message). If I understand it correctly it calls QCoreApplication::exit(…) which does return to the caller (it is event processing that stops).

This PR should now be ready for review.

@laanwj
Copy link
Member

laanwj commented Jul 17, 2017

If I understand it correctly it calls QCoreApplication::exit(…) which does return to the caller (it is event processing that stops).

Agreed - if you're not 100% sure that a function doesn't return, it's much better to err on the safe side and not specify it. From experience, functions with noreturn returning can result in some awful things, which might even be security critical (but at the least hard to debug), as it can fall through to apparently random code.

@TheBlueMatt
Copy link
Contributor

@practicalswift I'm confused, then, BitcoinApplication::handleRunawayException ends by calling ::exit (the global exit, not QCoreApplication::exit, no?)?

@practicalswift practicalswift force-pushed the noreturn branch 3 times, most recently from c340a51 to 536504c Compare July 17, 2017 23:05
@practicalswift
Copy link
Contributor Author

practicalswift commented Jul 17, 2017

@TheBlueMatt You're absolutely right! I was wrong about QCoreApplication::exit(…) being called. Sorry :-)

After applying 536504c8bef776902fa071dd76a37ef7037c1945 make check passes for all build configurations except HOST=x86_64-apple-darwin11, see https://travis-ci.org/bitcoin/bitcoin/builds/254651379. I don't understand why that is.

@theuni
Copy link
Member

theuni commented Jul 18, 2017

The attribute needs to be on the declaration rather than the definition.

@practicalswift
Copy link
Contributor Author

practicalswift commented Jul 18, 2017

@theuni Yes, I thought so but when applying d52e345a6e7526f516425b7547dbca534a884172 I got the parsing error qt/bitcoin.cpp:[…]: Parse error at ";" for all Qt-enabled builds, see https://travis-ci.org/bitcoin/bitcoin/jobs/254702626#L2290.

$ make V=1
[…]
QT_SELECT=qt5 /usr/lib/x86_64-linux-gnu/qt5/bin/moc -I. -I../src/config -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/include/x86_64-linux-gnu/qt5 -DHAVE_CONFIG_H -I. qt/bitcoin.cpp | \
  /bin/sed -e '/^\*\*.*Created:/d' -e '/^\*\*.*by:/d' > qt/bitcoin.moc
qt/bitcoin.cpp:233: Parse error at ";"
[…]
$ wc -c src/qt/bitcoin.moc
0 src/qt/bitcoin.moc
$ /usr/lib/x86_64-linux-gnu/qt5/bin/moc --version
moc 5.5.1

Qt:s moc being confused by the [[noreturn]] attribute? :-)

@practicalswift
Copy link
Contributor Author

practicalswift commented Jul 18, 2017

I've now excluded the commit touching handleRunawayException(…) (src/qt/bitcoin.cpp). Qt's moc is doing too much stuff behind the scenes for me to be comfortable doing that change :-)

This PR should now be ready for review.

@TheBlueMatt
Copy link
Contributor

utACK b82c55a

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Nov 21, 2019
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

# Conflicts:
#	src/test/test_bitcoin_main.cpp
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Dec 9, 2019
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

# Conflicts:
#	src/test/test_bitcoin_main.cpp
codablock added a commit to codablock/dash that referenced this pull request Dec 31, 2019
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 1, 2020
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 1, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

# Conflicts:
#	src/test/test_bitcoin_main.cpp
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 1, 2020
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

# Conflicts:
#	src/test/test_bitcoin_main.cpp
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 2, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport

10843 continued

Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 3, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport

10843 continued

Signed-off-by: Pasta <pasta@dashboost.org>
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 10, 2020
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport

10843 continued

Signed-off-by: Pasta <pasta@dashboost.org>
@practicalswift practicalswift deleted the noreturn branch April 10, 2021 19:32
fanquake added a commit that referenced this pull request Apr 13, 2021
003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to #10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 13, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 28, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 29, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 1, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 15, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 15, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 16, 2021
…cable

003929c refactor: add [[noreturn]] attribute where applicable (fanquake)

Pull request description:

  Similar to bitcoin#10843. We could build with `-Wmissing-noreturn`, however that would also mean modifying something like `--suppress-external-warnings` to suppress warnings for leveldb, which I don't think we want to do. In any case, the functions where this is applicable are only added/removed very rarely.

ACKs for top commit:
  vasild:
    ACK 003929c

Tree-SHA512: 33dfa6547d6b84f38a941f24d4c2effe8fde7b93dbc0b27a9309716420e4a879fdbe689d789fa5439d65f5f78292f89fd9dc1b61c97acf69316dfed954086705
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jan 29, 2022
…that will not return

b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift)

Pull request description:

  Add attribute `[[noreturn]]` (C++11) to functions that will not return.

  Rationale:
  * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code
  * Potentially enable additional compiler optimizations

Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
Signed-off-by: Pasta <pasta@dashboost.org>

Fixes for bitcoin#10843 backport

10843 continued

Signed-off-by: Pasta <pasta@dashboost.org>
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants