This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] clang-tidy (NFC)
ClosedPublic

Authored by aheejin on Jan 30 2019, 10:59 PM.

Details

Summary

This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*
(LLVM's default .clang-tidy list is the same except it does not have
modernize-*. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)

The common fixes are:

  • Variable names start with an uppercase letter
  • Function names start with a lowercase letter
  • Use auto when you use casts so the type is evident
  • Use inline initialization for class member variables
  • Use = default for empty constructors / destructors
  • Use using in place of typedef

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin created this revision.Jan 30 2019, 10:59 PM

I know LLVM does not encourage large-scale reformatting CLs. But as in my previous clang-format CL some months ago, the total changed LOC is around several hundred lines, so I'd like to try and hear opinions. Most of the changed lines are from renaming functions and variables. I'd also be happy to revert for the part of change people don't agree on or split this into multiple CLs, each of which possibly fixes smaller number of issues.

aheejin edited the summary of this revision. (Show Details)Jan 30 2019, 11:01 PM
aheejin updated this revision to Diff 184458.Jan 30 2019, 11:04 PM
  • Revert an unintended comment change
This revision is now accepted and ready to land.Jan 31 2019, 10:12 AM

Generally LGTM. I requested holding back on a few change. Hope this makes sense.

lib/MC/MCSectionWasm.cpp
17 ↗(On Diff #184458)

I guess you are removing this anchor because we have other methods below?

lib/MC/WasmObjectWriter.cpp
1318 ↗(On Diff #184458)

This looks wrong.. unless size is some kind of struct?

lib/Object/WasmObjectFile.cpp
1352 ↗(On Diff #184458)

I prefer the old version here.

1373 ↗(On Diff #184458)

Revert this?

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
83 ↗(On Diff #184458)

Can you explain this change?

278 ↗(On Diff #184458)

I prefer it was it was

lib/Target/WebAssembly/CMakeLists.txt
48 ↗(On Diff #184458)

What is this?

lib/Target/WebAssembly/MCTargetDesc/WebAssemblyAsmBackend.cpp
38 ↗(On Diff #184458)

Should we just remove this line?

lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.h
26 ↗(On Diff #184458)

Remove?

lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
246 ↗(On Diff #184458)

Revert.

lib/Target/WebAssembly/WebAssemblyAsmPrinter.h
61 ↗(On Diff #184458)

Revert this.. presumably its better to match the others.

lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
218 ↗(On Diff #184458)

It it worth it in this case?

lib/Target/WebAssembly/WebAssemblyFastISel.cpp
97 ↗(On Diff #184458)

Is this actually better? Perhaps revert this?

lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
326 ↗(On Diff #184458)

Revert? This seem unrelated.

lib/Target/WebAssembly/WebAssemblyISelLowering.h
104 ↗(On Diff #184458)

Perhaps lets stick with the ISel convention of calling everything "LowerXX" for now.

Better to match the convention than be locally style conformant I think

lib/Target/WebAssembly/WebAssemblyMCInstLower.h
34 ↗(On Diff #184458)

I think this mirror methods in several other classes (e.g. AsmPrinter) so perhaps should keep their names for now

lib/Target/WebAssembly/WebAssemblySelectionDAGInfo.h
24 ↗(On Diff #184458)

Remove?

lib/Target/WebAssembly/WebAssemblyTargetMachine.h
34 ↗(On Diff #184458)

Remove?

tools/obj2yaml/wasm2yaml.cpp
373 ↗(On Diff #184458)

revert

tlively added inline comments.Jan 31 2019, 11:40 AM
lib/Target/WebAssembly/CMakeLists.txt
48 ↗(On Diff #184458)

I actually put something useful in this file in https://reviews.llvm.org/D57498, so please revert this particular change.

lib/Target/WebAssembly/WebAssemblyFastISel.cpp
97 ↗(On Diff #184458)

FWIW, I'm not a fan to adding underscores to create new identifiers.

lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
326 ↗(On Diff #184458)

I think clang tidy just doesn't like identifiers that are all caps with underscores.

lib/Target/WebAssembly/WebAssemblyISelLowering.h
104 ↗(On Diff #184458)

+1

tools/llvm-objdump/WasmDump.cpp
51 ↗(On Diff #184458)

This should be reverted if we revert the other similar changes.

aheejin updated this revision to Diff 184649.EditedJan 31 2019, 5:18 PM
aheejin marked 25 inline comments as done.

Thank you for the feedback! Addressed comments:

  • Delete constructors/destructors marked as = default when not necessary
  • Revert all changes related to modernize-return-braced-init-list warning
  • Revert function name changes when they are inconsistent with overriden ones
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2019, 5:18 PM
aheejin added inline comments.Jan 31 2019, 5:18 PM
lib/MC/MCSectionWasm.cpp
17 ↗(On Diff #184458)

Its declaration is marked as = default in include/llvm/MC/MCSectionWasm.h, like

~MCSectionWasm() = default;
lib/MC/WasmObjectWriter.cpp
1318 ↗(On Diff #184458)

It returns MCExpr *.

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
83 ↗(On Diff #184458)

The warning was generated by modernize-use-override rule. But looks like there are debates on whether to do this on destructors and CPP core guidelines seems to explicitly discourage it. Reverted this change.

lib/Target/WebAssembly/CMakeLists.txt
48 ↗(On Diff #184458)

That file contained only a blank destructor

WebAssemblySelectionDAGInfo::~WebAssemblySelectionDAGInfo() {}

which I marked with = default in the header file. But because @tlively is using the file, I'll restore it.

lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
218 ↗(On Diff #184458)

Reverted it.

lib/Target/WebAssembly/WebAssemblyFastISel.cpp
97 ↗(On Diff #184458)

I'm not either. And also there are a lot of set*** style functions in LLVM codebase and not many functions are using this style argument name with an underscore. But I don't feel strongly about either option, so please let me know if you still prefer the original code.

lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
326 ↗(On Diff #184458)

clang-tidy does not have problems with all caps but does not like underscores. Still revert?

aheejin marked an inline comment as done.Jan 31 2019, 5:19 PM
aheejin added inline comments.
lib/MC/MCSectionWasm.cpp
17 ↗(On Diff #184458)

By the way it was also deleted from the header file anyway.

aheejin updated this revision to Diff 184650.Jan 31 2019, 5:24 PM
  • Deleted ~MCSectionWasm() = default
aheejin marked an inline comment as done.Jan 31 2019, 5:25 PM
aheejin added inline comments.
lib/MC/MCWasmObjectTargetWriter.cpp
17 ↗(On Diff #184649)

Hmm, I've deleted all unnecessary = default destructors, but I guess they had purposes..? Do you know what this is for?

sbc100 added inline comments.Jan 31 2019, 5:48 PM
lib/MC/MCWasmObjectTargetWriter.cpp
17 ↗(On Diff #184649)

As assume its just the above reason "to pin the vtable to this object file".

See:
https://llvm.org/docs/CodingStandards.html#provide-a-virtual-method-anchor-for-classes-in-headers

aheejin edited the summary of this revision. (Show Details)Jan 31 2019, 6:57 PM
aheejin updated this revision to Diff 184683.Jan 31 2019, 10:40 PM
  • Restored out-of-line destructor anchors w/ = default keyword
aheejin edited the summary of this revision. (Show Details)Feb 1 2019, 11:41 AM

Does anyone have other concerns?

aheejin updated this revision to Diff 184930.Feb 2 2019, 11:21 PM
aheejin marked an inline comment as done.
  • Revert more modernize-return-braced-init-list changes
  • Remove .clang-tidy that was added by mistake
aheejin added inline comments.Feb 2 2019, 11:21 PM
lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
1057 ↗(On Diff #184683)

Because we decided not to fix modernize-return-braced-init-list warning, I reverted a pre-existing case for consistency.

Will land this if no one has other concerns.

This revision was automatically updated to reflect the committed changes.