Bug 79227 - Questionable -Wmisleading-indentation diagnostic in HSAIL-Tools
Summary: Questionable -Wmisleading-indentation diagnostic in HSAIL-Tools
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.2.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2017-01-25 11:14 UTC by Thomas Schwinge
Modified: 2021-09-16 21:48 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
reduced "HSAILValidatorBase.cpp" file (545 bytes, text/plain)
2017-01-25 11:14 UTC, Thomas Schwinge
Details
Patch to tweak Wmisleading indentation (629 bytes, patch)
2017-01-25 15:41 UTC, David Malcolm
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwinge 2017-01-25 11:14:32 UTC
Created attachment 40576 [details]
reduced "HSAILValidatorBase.cpp" file

I don't have any strong opinion, so I'm asking you to please check the following.

Compiling <https://github.com/HSAFoundation/HSAIL-Tools>, commit 12220b0ddccd4559e979906bfd65fb49fcdd7854 with Ubuntu GCC 6.2.0-5ubuntu12, the build aborts:

    [...]/libHSAIL/HSAILValidatorBase.cpp: In member function 'virtual bool HSAIL_ASM::PropValidator::checkOperandKind(HSAIL_ASM::Inst, unsigned int, unsigned int*, unsigned int, bool) const':
    [...]/libHSAIL/HSAILValidatorBase.cpp:395:37: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
             case OPERAND_VAL_FUNC:      if (isCodeRef(opr, BRIG_KIND_DIRECTIVE_FUNCTION) ||
                                         ^~
    [...]/libHSAIL/HSAILValidatorBase.cpp:396:110: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
                                             isCodeRef(opr, BRIG_KIND_DIRECTIVE_INDIRECT_FUNCTION))  return true; break;
                                                                                                                  ^~~~~
    cc1plus: all warnings being treated as errors

I'm attaching a reduced "HSAILValidatorBase.cpp" file, showing the issue for both C and C++ compilation.

Should the code be considered well-formed enough to not warn in this case?
Comment 1 David Malcolm 2017-01-25 15:10:26 UTC
Some notes:

There are 7 cases in the reproducer, but it only warns for the 3rd case (lines 34-35).

In each of the 7 cases in the reproducer, NEXT_STMT_LOC and BODY_LOC are on the same line:

  /* If NEXT_STMT_LOC and BODY_LOC are on the same line, consider
     the location of the guard.

Case 3 matches the following conditional, and thus warns:

      if (guard_exploc.line < body_exploc.line)
	/* The guard is on a line before a line that contains both
	   the body and the next stmt.  */
	return true;

whereas the other cases match this conditional:

      else if (guard_exploc.line == body_exploc.line)
	{
	  /* They're all on the same line.  */

and try this heuristic:

	  /* Heuristic: only warn if the guard is the first thing
	     on its line.  */
	  if (guard_vis_column == guard_line_first_nws)
	    return true;

...which doesn't match, hence we don't warn for them.
Comment 2 David Malcolm 2017-01-25 15:41:44 UTC
Created attachment 40579 [details]
Patch to tweak Wmisleading indentation

This patch removes the "(guard_exploc.line == body_exploc.line)" condition from the:
	  /* Heuristic: only warn if the guard is the first thing
	     on its line.  */

and hence silences the warning from the reproducer.  It doesn't introduce any regressions in the testsuite (only tested briefly, though).

[Would need ChangeLog, and testsuite coverage]


Patrick, any thoughts?