Commit 41b072b6 by Nico Weber Committed by Commit Bot

Prepare for -Wimplicit-fallthrough in ANGLE.

Disable the warning for flex-generated output, which contains lots of intentional fallthrough. Fixes a bug where GL_SAMPLE_ALPHA_TO_ONE_EXT would fall through to GL_COVERAGE_MODULATION_CHROMIUM and hence behave like that. Fixes a bug in the D3D9 state management where invalidating DIRTY_BIT_POLYGON_OFFSET would also invalidate the stencil bits. One somewhat common incorrect pattern in ANGLE is nested switch statements that look like so: switch (a) { case a1: switch (b) { case b1: ... break; } case a2: ... } The assumption here seems to be that the breakk exits the outer case (here a1), while it in fact only exits the inner switch, so that we fall through to a2. In most places, I fixed this by adding an explicit `break` after the inner switch. This fixes a bug wher GL_PATH_JOIN_STYLE_CHROMIUM would fall through to GL_PATH_MITER_LIMIT_CHROMIUM in validation (but since the join style enum is always > 0, this happened to not have an effect in practice). This also fixes 87 bugs in GetLoadFunctionsMap() where invalid values would previously return an unrelated function map instead of the empty load function map. Bug: chromium:810767 Change-Id: Ib51388c73fbfc229160e2c10f8fb9364cc7c996c Reviewed-on: https://chromium-review.googlesource.com/911529 Commit-Queue: Nico Weber <thakis@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 61773640
//
// Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// aligned_memory: Defines ANGLE_FALLTHROUGH. Do not include in public headers.
//
#ifndef COMMON_ANGLE_FALLTHROUGH_H_
#define COMMON_ANGLE_FALLTHROUGH_H_
// When clang suggests inserting [[clang::fallthrough]], it first checks if
// it knows of a macro expanding to it, and if so suggests inserting the
// macro. This means that this macro must be used only in code internal
// to ANGLE, so that ANGLE's user code doesn't end up getting suggestions
// for ANGLE_FALLTHROUGH instead of the user-specific fallthrough macro.
// So do not include this header in any of ANGLE's public headers.
#if defined(__clang__)
#define ANGLE_FALLTHROUGH [[clang::fallthrough]]
#else
#define ANGLE_FALLTHROUGH
#endif
#endif // COMMON_ANGLE_FALLTHROUGH_H_
......@@ -911,6 +911,10 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#elif defined(_MSC_VER)
#pragma warning(disable: 4244)
#endif
#if defined(__clang__)
// Flex uses `/*FALLTHROUGH*/` instead of dedicated statements.
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
// Workaround for flex using the register keyword, deprecated in C++11.
#ifdef __cplusplus
......
......@@ -38,6 +38,10 @@ IF YOU MODIFY THIS FILE YOU ALSO NEED TO RUN generate_parser.sh.
#elif defined(_MSC_VER)
#pragma warning(disable: 4244)
#endif
#if defined(__clang__)
// Flex uses `/*FALLTHROUGH*/` instead of dedicated statements.
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
// Workaround for flex using the register keyword, deprecated in C++11.
#ifdef __cplusplus
......
......@@ -105,6 +105,7 @@ class PullGradient : public TIntermTraverser
case EOpDFdy:
case EOpFwidth:
onGradient();
break;
default:
break;
}
......
......@@ -6,6 +6,7 @@
#include "compiler/translator/EmulatePrecision.h"
#include "common/angle_fallthrough.h"
#include "compiler/translator/FunctionLookup.h"
#include <memory>
......@@ -639,6 +640,7 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node)
{
break;
}
ANGLE_FALLTHROUGH;
default:
TIntermNode *parent = getParentNode();
if (canRoundFloat(node->getType()) && ParentUsesResult(parent, node) &&
......
......@@ -1588,6 +1588,7 @@ bool TIntermBinary::hasConstantValue() const
{
return true;
}
break;
}
default:
break;
......
......@@ -4918,6 +4918,7 @@ TIntermTyped *TParseContext::createUnaryMath(TOperator op,
unaryOpError(loc, GetOperatorString(op), child->getCompleteString());
return nullptr;
}
break;
// Operators for built-ins are already type checked against their prototype.
default:
break;
......
......@@ -26,9 +26,9 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
// Ignore errors in auto-generated code.
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wswitch-enum"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wswitch-enum"
#elif defined(_MSC_VER)
#pragma warning(disable: 4005)
#pragma warning(disable: 4065)
......@@ -38,6 +38,9 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
#pragma warning(disable: 4701)
#pragma warning(disable: 4702)
#endif
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
}
%{
......
......@@ -11,9 +11,9 @@
// Ignore errors in auto-generated code.
#if defined(__GNUC__)
#pragma GCC diagnostic ignored "-Wswitch-enum"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wswitch-enum"
#elif defined(_MSC_VER)
#pragma warning(disable: 4005)
#pragma warning(disable: 4065)
......@@ -23,6 +23,9 @@
#pragma warning(disable: 4701)
#pragma warning(disable: 4702)
#endif
#if defined(__clang__)
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
#endif
......
......@@ -1766,9 +1766,10 @@ void State::getFloatv(GLenum pname, GLfloat *params)
break;
case GL_SAMPLE_ALPHA_TO_ONE_EXT:
*params = static_cast<GLfloat>(mSampleAlphaToOne);
break;
case GL_COVERAGE_MODULATION_CHROMIUM:
params[0] = static_cast<GLfloat>(mCoverageModulation);
break;
params[0] = static_cast<GLfloat>(mCoverageModulation);
break;
default:
UNREACHABLE();
break;
......@@ -2051,6 +2052,7 @@ void State::getIntegerv(const Context *context, GLenum pname, GLint *params)
break;
case GL_SAMPLE_ALPHA_TO_ONE_EXT:
*params = static_cast<GLint>(mSampleAlphaToOne);
break;
case GL_COVERAGE_MODULATION_CHROMIUM:
*params = static_cast<GLint>(mCoverageModulation);
break;
......
......@@ -1032,6 +1032,7 @@ void StateManager11::syncState(const gl::Context *context, const gl::State::Dirt
{
invalidateCurrentValueAttrib(attribIndex);
}
break;
}
default:
break;
......
......@@ -250,6 +250,7 @@ void StateManager9::syncState(const gl::State &state, const gl::State::DirtyBits
{
mDirtyBits.set(DIRTY_BIT_DEPTH_BIAS);
}
break;
}
case gl::State::DIRTY_BIT_DEPTH_MASK:
if (state.getDepthStencilState().depthMask != mCurDepthStencilState.depthMask)
......
......@@ -80,12 +80,11 @@ LoadFunctionMap GetLoadFunctionsMap(GLenum {internal_format}, Format::ID {angle_
{{
{switch_data}
default:
{{
static LoadFunctionMap emptyLoadFunctionsMap;
return emptyLoadFunctionsMap;
}}
break;
}}
// clang-format on
static LoadFunctionMap emptyLoadFunctionsMap;
return emptyLoadFunctionsMap;
}} // GetLoadFunctionsMap
......@@ -163,15 +162,21 @@ def parse_json(json_data):
if do_switch:
table_data += s + 'default:\n'
has_break_in_switch = False
if angle_format_unknown in angle_to_type_map:
table_data += s + ' return ' + unknown_func_name(internal_format) + ';\n'
load_functions_data += get_unknown_load_func(angle_to_type_map, internal_format)
else:
has_break_in_switch = True
table_data += s + ' break;\n'
if do_switch:
s = s[4:]
table_data += s + '}\n'
if has_break_in_switch:
# If the inner switch contains a break statement, add a break
# statement after the switch as well.
table_data += s + 'break;\n'
s = s[4:]
table_data += s + '}\n'
......
......@@ -445,6 +445,7 @@ Error ValidateGetPlatformDisplayCommon(EGLenum platform,
"platform type of EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE or "
"EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE.";
}
break;
default:
break;
}
......@@ -2473,6 +2474,7 @@ Error ValidateSurfaceAttrib(const Display *display,
default:
return EglBadAttribute() << "Invalid multisample resolve type.";
}
break;
case EGL_SWAP_BEHAVIOR:
switch (value)
......@@ -2491,6 +2493,7 @@ Error ValidateSurfaceAttrib(const Display *display,
default:
return EglBadAttribute() << "Invalid swap behaviour.";
}
break;
default:
return EglBadAttribute() << "Invalid surface attribute.";
......
......@@ -3328,6 +3328,7 @@ bool ValidatePathParameterfCHROMIUM(Context *context, GLuint path, GLenum pname,
context->handleError(InvalidEnum() << "Invalid join style.");
return false;
}
break;
case GL_PATH_MITER_LIMIT_CHROMIUM:
if (value < 0.0f)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment