Skip to content

Commit

Permalink
Make default initialization explicit
Browse files Browse the repository at this point in the history
Coverity (a static analysis tool) reported that the emitted 'Features'
variable inside emitComputeAvailableFeatures in TableGen might be
unitialized.
Silence this warning by adding brackets for the default initialization.
Adapt test cases to take additional brackets into account.
  • Loading branch information
Martin Wehking authored and ldrumm committed Apr 23, 2024
1 parent c52b18d commit b817451
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions llvm/test/TableGen/GlobalISelEmitter.td
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def HasC : Predicate<"Subtarget->hasC()"> { let RecomputePerFunction = 1; }

// CHECK-LABEL: PredicateBitset MyTargetInstructionSelector::
// CHECK-NEXT: computeAvailableModuleFeatures(const MyTargetSubtarget *Subtarget) const {
// CHECK-NEXT: PredicateBitset Features;
// CHECK-NEXT: PredicateBitset Features{};
// CHECK-NEXT: if (Subtarget->hasA())
// CHECK-NEXT: Features.set(Feature_HasABit);
// CHECK-NEXT: if (Subtarget->hasB())
Expand All @@ -120,7 +120,7 @@ def HasC : Predicate<"Subtarget->hasC()"> { let RecomputePerFunction = 1; }

// CHECK-LABEL: PredicateBitset MyTargetInstructionSelector::
// CHECK-NEXT: computeAvailableFunctionFeatures(const MyTargetSubtarget *Subtarget, const MachineFunction *MF) const {
// CHECK-NEXT: PredicateBitset Features;
// CHECK-NEXT: PredicateBitset Features{};
// CHECK-NEXT: if (Subtarget->hasC())
// CHECK-NEXT: Features.set(Feature_HasCBit);
// CHECK-NEXT: return Features;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/TableGen/GlobalISelEmitterHwModes.td
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class I<dag OOps, dag IOps, list<dag> Pat>

// CHECK-LABEL: PredicateBitset MyTargetInstructionSelector::
// CHECK-NEXT: computeAvailableModuleFeatures(const MyTargetSubtarget *Subtarget) const {
// CHECK-NEXT: PredicateBitset Features;
// CHECK-NEXT: PredicateBitset Features{};
// CHECK-NEXT: if (!((Subtarget->has64())))
// CHECK-NEXT: Features.set(Feature_HwMode1Bit);
// CHECK-NEXT: if ((Subtarget->has64()))
Expand All @@ -95,7 +95,7 @@ class I<dag OOps, dag IOps, list<dag> Pat>

// CHECK-LABEL: PredicateBitset MyTargetInstructionSelector::
// CHECK-NEXT: computeAvailableFunctionFeatures(const MyTargetSubtarget *Subtarget, const MachineFunction *MF) const {
// CHECK-NEXT: PredicateBitset Features;
// CHECK-NEXT: PredicateBitset Features{};
// CHECK-NEXT: return Features;
// CHECK-NEXT: }

Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void SubtargetFeatureInfo::emitComputeAvailableFeatures(
if (!ExtraParams.empty())
OS << ", " << ExtraParams;
OS << ") const {\n";
OS << " PredicateBitset Features;\n";
OS << " PredicateBitset Features{};\n";
for (const auto &SF : SubtargetFeatures) {
const SubtargetFeatureInfo &SFI = SF.second;
StringRef CondStr = SFI.TheDef->getValueAsString("CondString");
Expand Down

0 comments on commit b817451

Please sign in to comment.