Commit b5db2b49 by Nico Weber Committed by Commit Bot

Enable -Wimplicit-fallthrough for ANGLE.

Also teach MSVC that ANGLE_CRASH() can't return. Also fix instances of the warning in build configurations where UNREACHABLE() can return (e.g. release without dcheck_always_on or debug). If the UNREACHABLE()s are truly unreachable, this change has no behavior change. Bug: chromium:810767 Change-Id: I68f3587cf3e268c3ef634dce7ae3d70399859d0f Reviewed-on: https://chromium-review.googlesource.com/914842Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNico Weber <thakis@chromium.org> Commit-Queue: Nico Weber <thakis@chromium.org>
parent 4edce336
......@@ -99,9 +99,6 @@ config("extra_warnings") {
cflags += [
# Remove when crbug.com/428099 is resolved.
"-Winconsistent-missing-override",
# TODO(thakis): Consider enabling this, https://crbug.com/807632
"-Wno-implicit-fallthrough",
]
}
}
......
//
// 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_
......@@ -220,14 +220,16 @@ std::ostream &FmtHexInt(std::ostream &os, T value)
#if defined(COMPILER_GCC) || defined(__clang__)
#define ANGLE_CRASH() __builtin_trap()
#else
#define ANGLE_CRASH() ((void)(*(volatile char *)0 = 0))
#define ANGLE_CRASH() ((void)(*(volatile char *)0 = 0)), __assume(0)
#endif
#if !defined(NDEBUG)
#define ANGLE_ASSERT_IMPL(expression) assert(expression)
#define ANGLE_ASSERT_IMPL_IS_NORETURN 0
#else
// TODO(jmadill): Detect if debugger is attached and break.
#define ANGLE_ASSERT_IMPL(expression) ANGLE_CRASH()
#define ANGLE_ASSERT_IMPL_IS_NORETURN 1
#endif // !defined(NDEBUG)
// A macro asserting a condition and outputting failures to the debug log
......@@ -236,6 +238,7 @@ std::ostream &FmtHexInt(std::ostream &os, T value)
(expression ? static_cast<void>(0) : ((ERR() << "\t! Assert failed in " << __FUNCTION__ << "(" \
<< __LINE__ << "): " << #expression), \
ANGLE_ASSERT_IMPL(expression)))
#define UNREACHABLE_IS_NORETURN ANGLE_ASSERT_IMPL_IS_NORETURN
#else
// These are just dummy values.
#define COMPACT_ANGLE_LOG_EX_ASSERT(ClassName, ...) \
......@@ -249,6 +252,7 @@ constexpr LogSeverity LOG_ASSERT = LOG_EVENT;
#define ASSERT(condition) \
ANGLE_LAZY_STREAM(ANGLE_LOG_STREAM(ASSERT), false ? !(condition) : false) \
<< "Check failed: " #condition ". "
#define UNREACHABLE_IS_NORETURN 0
#endif // defined(ANGLE_ENABLE_ASSERTS)
#define UNUSED_VARIABLE(variable) ((void)variable)
......
......@@ -4993,10 +4993,9 @@ bool TParseContext::binaryOpCommonCheck(TOperator op,
case EOpIndexDirect:
case EOpIndexIndirect:
break;
case EOpIndexDirectStruct:
UNREACHABLE();
default:
ASSERT(op != EOpIndexDirectStruct);
error(loc, "Invalid operation for variables with an opaque type",
GetOperatorString(op));
return false;
......
......@@ -96,6 +96,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_2D_SNORM;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtIImage2D:
......@@ -109,6 +112,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_2D_INT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtUImage2D:
......@@ -123,6 +129,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_2D_UINT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtImage3D:
......@@ -139,6 +148,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_3D_SNORM;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtIImage3D:
......@@ -152,6 +164,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_3D_INT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtUImage3D:
......@@ -165,6 +180,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_3D_UINT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtImage2DArray:
......@@ -182,6 +200,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_2D_ARRAY_SNORM;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtIImage2DArray:
......@@ -196,6 +217,9 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_2D_ARRAY_INT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
case EbtUImage2DArray:
......@@ -210,12 +234,17 @@ HLSLTextureGroup TextureGroup(const TBasicType type, TLayoutImageInternalFormat
return HLSL_TEXTURE_2D_ARRAY_UINT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
}
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return HLSL_TEXTURE_UNKNOWN;
#endif
}
return HLSL_TEXTURE_UNKNOWN;
}
const char *TextureString(const HLSLTextureGroup textureGroup)
......@@ -372,6 +401,9 @@ const char *TextureTypeSuffix(const TBasicType type, TLayoutImageInternalFormat
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtIImageCube:
{
......@@ -385,6 +417,9 @@ const char *TextureTypeSuffix(const TBasicType type, TLayoutImageInternalFormat
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtUImageCube:
{
......@@ -398,11 +433,18 @@ const char *TextureTypeSuffix(const TBasicType type, TLayoutImageInternalFormat
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
default:
// All other types are identified by their group suffix
return TextureGroupSuffix(type, imageInternalFormat);
}
#if !UNREACHABLE_IS_NORETURN
UNREACHABLE();
return "_TTS_invalid_";
#endif
}
HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
......@@ -426,6 +468,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtIImage2D:
{
......@@ -439,6 +484,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtUImage2D:
{
......@@ -453,6 +501,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtImage3D:
{
......@@ -469,6 +520,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtIImage3D:
{
......@@ -482,6 +536,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtUImage3D:
{
......@@ -495,6 +552,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtImage2DArray:
case EbtImageCube:
......@@ -512,6 +572,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtIImage2DArray:
case EbtIImageCube:
......@@ -526,6 +589,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtUImage2DArray:
case EbtUImageCube:
......@@ -540,6 +606,9 @@ HLSLRWTextureGroup RWTextureGroup(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
default:
UNREACHABLE();
......@@ -660,6 +729,9 @@ const char *RWTextureTypeSuffix(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtIImageCube:
{
......@@ -673,6 +745,9 @@ const char *RWTextureTypeSuffix(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
case EbtUImageCube:
{
......@@ -686,11 +761,18 @@ const char *RWTextureTypeSuffix(const TBasicType type,
default:
UNREACHABLE();
}
#if !UNREACHABLE_IS_NORETURN
break;
#endif
}
default:
// All other types are identified by their group suffix
return TextureGroupSuffix(type, imageInternalFormat);
}
#if !UNREACHABLE_IS_NORETURN
UNREACHABLE();
return "_RWTS_invalid_";
#endif
}
TString DecorateField(const ImmutableString &string, const TStructure &structure)
......
......@@ -216,6 +216,9 @@ GLenum GLVariableType(const TType &type)
return GL_FLOAT_VEC4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
}
else if (type.isMatrix())
......@@ -233,6 +236,9 @@ GLenum GLVariableType(const TType &type)
return GL_FLOAT_MAT2x4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
case 3:
......@@ -246,6 +252,9 @@ GLenum GLVariableType(const TType &type)
return GL_FLOAT_MAT3x4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
case 4:
......@@ -259,10 +268,16 @@ GLenum GLVariableType(const TType &type)
return GL_FLOAT_MAT4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
}
else
......@@ -284,6 +299,9 @@ GLenum GLVariableType(const TType &type)
return GL_INT_VEC4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
}
else
......@@ -306,6 +324,9 @@ GLenum GLVariableType(const TType &type)
return GL_UNSIGNED_INT_VEC4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
}
else
......@@ -328,6 +349,9 @@ GLenum GLVariableType(const TType &type)
return GL_BOOL_VEC4;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return GL_NONE;
#endif
}
}
else
......@@ -554,7 +578,9 @@ InterpolationType GetInterpolationType(TQualifier qualifier)
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return INTERPOLATION_SMOOTH;
#endif
}
}
......@@ -614,7 +640,9 @@ TType GetShaderVariableBasicType(const sh::ShaderVariable &var)
return TType(EbtUInt, 4);
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return TType();
#endif
}
}
......
......@@ -438,7 +438,9 @@ bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
return true;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return false;
#endif
}
}
......@@ -1269,7 +1271,9 @@ AttributeType GetAttributeType(GLenum enumValue)
return ATTRIBUTE_MAT4x3;
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return ATTRIBUTE_FLOAT;
#endif
}
}
......@@ -1306,7 +1310,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_SBYTE4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_UNSIGNED_BYTE:
switch (components)
......@@ -1337,7 +1343,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_UBYTE4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_SHORT:
switch (components)
......@@ -1368,7 +1376,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_SSHORT4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_UNSIGNED_SHORT:
switch (components)
......@@ -1399,7 +1409,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_USHORT4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_INT:
switch (components)
......@@ -1430,7 +1442,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_SINT4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_UNSIGNED_INT:
switch (components)
......@@ -1461,7 +1475,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_UINT4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_FLOAT:
switch (components)
......@@ -1476,7 +1492,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_FLOAT4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_HALF_FLOAT:
switch (components)
......@@ -1491,7 +1509,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_HALF4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_FIXED:
switch (components)
......@@ -1506,7 +1526,9 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_FIXED4;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
case GL_INT_2_10_10_10_REV:
if (pureInteger)
......@@ -1522,9 +1544,10 @@ VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint c
return VERTEX_FORMAT_UINT210;
default:
UNREACHABLE();
break;
#if !UNREACHABLE_IS_NORETURN
return VERTEX_FORMAT_INVALID;
#endif
}
return VERTEX_FORMAT_UBYTE1;
}
VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
......@@ -2116,7 +2139,9 @@ size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
case VERTEX_FORMAT_INVALID:
default:
UNREACHABLE();
#if !UNREACHABLE_IS_NORETURN
return 0;
#endif
}
}
......
......@@ -547,7 +547,6 @@ gl::Error Blit9::setFormatConvertShaders(GLenum destFormat,
switch (destFormat)
{
default: UNREACHABLE();
case GL_RGBA:
case GL_BGRA_EXT:
multConst[X] = 1;
......@@ -625,6 +624,8 @@ gl::Error Blit9::setFormatConvertShaders(GLenum destFormat,
addConst[Z] = 0;
addConst[W] = 0;
break;
default: UNREACHABLE();
}
mRenderer->getDevice()->SetPixelShaderConstantF(0, psConst, 2);
......
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