Skip to content

Squelch some dead code warnings. #13186

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

Merged
merged 1 commit into from
Dec 11, 2017
Merged

Squelch some dead code warnings. #13186

merged 1 commit into from
Dec 11, 2017

Conversation

rudkx
Copy link
Contributor

@rudkx rudkx commented Nov 30, 2017

No description provided.

@rudkx
Copy link
Contributor Author

rudkx commented Nov 30, 2017

@swift-ci Please smoke test

@@ -393,7 +393,7 @@ LLVM_ATTRIBUTE_NOINLINE
static void debugFailWithAssertion() {
// This assertion should always fail, per the user's request, and should
// not be converted to llvm_unreachable.
assert(0 && "This is an assertion!");
assert((0) && "This is an assertion!");
Copy link
Contributor

Choose a reason for hiding this comment

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

llvm_unreachable is compiled in the same cases as asserts, so there's no point in not making this llvm_unreachable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Presumably there's a reason why this specifically says it should not be llvm_unreachable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, a misunderstanding on the author's part :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the original patch did this:

commit 9df53c5c71b5bb9252ee5d13cd349295a6d19602
Author: Connor Wakamo <[email protected]>
Date:   Fri Feb 7 22:30:40 2014 +0000

    [frontend] Switch -debug-assert-* from llvm_unreachable() to assert(0).
    
    Swift SVN r13656

Copy link
Contributor

Choose a reason for hiding this comment

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

The flag is only used in one test, test/Driver/assert.swift. If the test passes with it changed to an llvm_unreachable I would keep it that way.

Copy link
Contributor Author

@rudkx rudkx Dec 1, 2017

Choose a reason for hiding this comment

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

llvm_unreachable actually has an effect in no-asserts build (which is why I almost never introduce it in places where someone previously had an assert, and almost certainly why it was not used above).

It becomes __builtin_unreachable() which the optimizer takes to mean "party on!", which in practice for LLVM I believe means it deletes all code following this point until the next join in control flow (although I could be wrong - it does not seem to turn into ud2 on x86, but it definitely deletes useful code after that point, resulting in unpredictable crashes happening later).

[edited a few times to conditionalize statements :)]

@@ -184,11 +184,11 @@ ParserResult<TypeRepr> Parser::parseTypeSimple(Diag<> MessageID,
TypeSpecifier = VarDecl::Specifier::InOut;
} else if (Tok.is(tok::identifier)) {
if (Tok.getRawText().equals("__shared")) {
assert(false);
assert((false));
Copy link
Contributor

Choose a reason for hiding this comment

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

This and all the others should be llvm_unreachable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, true. Blindly trying to kill off warnings without paying enough attention. Thanks for noticing.

Copy link
Member

@rintaro rintaro Dec 1, 2017

Choose a reason for hiding this comment

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

Ah sorry, I removed this part in #13173

Fix up some dead code warnings as well as a warning for testing
whether an unsigned number is non-negative (which it always is).
@rudkx
Copy link
Contributor Author

rudkx commented Dec 11, 2017

@swift-ci Please smoke test

@rudkx rudkx merged commit eebde10 into swiftlang:master Dec 11, 2017
@rudkx rudkx deleted the fix-warnings branch December 11, 2017 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants