This is an archive of the discontinued LLVM Phabricator instance.

Add maybe-unused attribute to a variable.
AbandonedPublic

Authored by nickdesaulniers on Jul 24 2018, 1:12 PM.

Details

Reviewers
srhines
pirama
Summary

Mark a variable as maybe-unused to prevent a -Wunused-but-set-variable warning in optimized builds where asserts are removed.Test/first commit to check setup and understand patch submission process.

Diff Detail

Event Timeline

oops, ok, looks I should not use git submodules? I thought arc asked if I wanted to skip submodule changes...

nickdesaulniers retitled this revision from Mark a variable as maybe-unused to prevent a -Wunused-by-set-variable warning in optimized builds where asserts are removed. Test/first commit to check setup and understand patch submission process. to Add maybe-unused attribute to a variable..Jul 24 2018, 1:16 PM
nickdesaulniers edited the summary of this revision. (Show Details)

Definitely deal with the submodule stuff. We don't want a new file checked in for tools/clang.

In the commit message did you mean "unused-but-set" instead of "unused-by-set"?

lib/IR/SafepointIRVerifier.cpp
87

Did you run clang-format on this? I think it belongs on the same line for LLVM coding style.

nickdesaulniers edited the summary of this revision. (Show Details)Jul 24 2018, 1:29 PM
lib/IR/SafepointIRVerifier.cpp
87

Running $ clang-format -i lib/IR/SafepointIRVerifier.cpp makes quite a few changes to this file (and puts the attribute on the same line). Is that ok? I assume clang-format can find the .clang-format in the top of the tree (using the LLVM style, as opposed to whatever the defaults are)?

dblaikie added inline comments.
lib/IR/SafepointIRVerifier.cpp
87

You can run clang-format on only the changed lines, rather than the whole file. There's also the git-clang-format script that can format only the lines changed in a git branch.

Though also, usually the way LLVM would fix these sort of issues is by including a separate statement "(void)Listed;" just before the assertion. (that way, if the assertion is removed hopefully someone would remove the void cast, which would allow the compiler to identify that the variable was unread, etc)