diff --git a/lib/CliftEmitC/CEmitter.cpp b/lib/CliftEmitC/CEmitter.cpp index bc1336d4d..50e1719c4 100644 --- a/lib/CliftEmitC/CEmitter.cpp +++ b/lib/CliftEmitC/CEmitter.cpp @@ -82,10 +82,18 @@ private: return Name; } - std::optional commentableReturnValueGuard() { + std::optional + commentableReturnValueGuard(DeclaratorInfo const *Declarator) { if (OutermostFunctionType == nullptr) return std::nullopt; + // Only emitting the return value guard when parameters are available might + // look weird at the first sight, but when we are emitting a prototype + // without parameter information (the typedef), it's weird to allow adding + // comments to a return type that will show up elsewhere. + if (not Declarator->Parameters) + return std::nullopt; + auto FTHandle = OutermostFunctionType.getHandle(); auto FTLoc = pipeline::locationFromString(revng::ranks::TypeDefinition, FTHandle); @@ -141,7 +149,7 @@ private: } { - auto Guard = commentableReturnValueGuard(); + auto Guard = commentableReturnValueGuard(Declarator); // Recurse through the declaration, pushing each level onto the stack // until a terminal type is encountered. Primitive types as well as