123 changes: 109 additions & 14 deletions clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1770,17 +1770,29 @@ struct FormatStyle {
/// \version 3.8
BraceWrappingFlags BraceWrapping;

/// If ``true``, concept will be placed on a new line.
/// \code
/// true:
/// template<typename T>
/// concept ...
///
/// false:
/// template<typename T> concept ...
/// \endcode
/// Different ways to break before concept declarations.
enum BreakBeforeConceptDeclarationsStyle {
/// Keep the template declaration line together with ``concept``.
/// \code
/// template <typename T> concept C = ...;
/// \endcode
BBCDS_Never,
/// Breaking between template declaration and ``concept`` is allowed. The
/// actual behavior depends on the content and line breaking rules and
/// penalities.
BBCDS_Allowed,
/// Always break before ``concept``, putting it in the line after the
/// template declaration.
/// \code
/// template <typename T>
/// concept C = ...;
/// \endcode
BBCDS_Always,
};

/// The concept declaration style to use.
/// \version 13
bool BreakBeforeConceptDeclarations;
BreakBeforeConceptDeclarationsStyle BreakBeforeConceptDeclarations;

/// If ``true``, ternary operators will be placed after line breaks.
/// \code
Expand Down Expand Up @@ -2509,7 +2521,8 @@ struct FormatStyle {
/// \version 12
IndentExternBlockStyle IndentExternBlock;

/// Indent the requires clause in a template
/// Indent the requires clause in a template. This only applies when
/// ``RequiresClausePosition`` is ``OwnLine``, or ``WithFollowing``.
/// \code
/// true:
/// template <typename It>
Expand All @@ -2526,7 +2539,7 @@ struct FormatStyle {
/// }
/// \endcode
/// \version 13
bool IndentRequires;
bool IndentRequiresClause;

/// The number of columns to use for indentation.
/// \code
Expand Down Expand Up @@ -3116,6 +3129,87 @@ struct FormatStyle {
/// \version 14
bool RemoveBracesLLVM;

/// \brief The possible positions for the requires clause. The
/// ``IndentRequires`` option is only used if the ``requires`` is put on the
/// start of a line.
enum RequiresClausePositionStyle {
/// Always put the ``requires`` clause on its own line.
/// \code
/// template <typename T>
/// requires C<T>
/// struct Foo {...
///
/// template <typename T>
/// requires C<T>
/// void bar(T t) {...
///
/// template <typename T>
/// void baz(T t)
/// requires C<T>
/// {...
/// \endcode
RCPS_OwnLine,
/// Try to put the clause together with the preceding part of a declaration.
/// For class templates: stick to the template declaration.
/// For function templates: stick to the template declaration.
/// For function declaration followed by a requires clause: stick to the
/// parameter list.
/// \code
/// template <typename T> requires C<T>
/// struct Foo {...
///
/// template <typename T> requires C<T>
/// void bar(T t) {...
///
/// template <typename T>
/// void baz(T t) requires C<T>
/// {...
/// \endcode
RCPS_WithPreceding,
/// Try to put the ``requires`` clause together with the class or function
/// declaration.
/// \code
/// template <typename T>
/// requires C<T> struct Foo {...
///
/// template <typename T>
/// requires C<T> void bar(T t) {...
///
/// template <typename T>
/// void baz(T t)
/// requires C<T> {...
/// \endcode
RCPS_WithFollowing,
/// Try to put everything in the same line if possible. Otherwise normal
/// line breaking rules take over.
/// \code
/// // Fitting:
/// template <typename T> requires C<T> struct Foo {...
///
/// template <typename T> requires C<T> void bar(T t) {...
///
/// template <typename T> void bar(T t) requires C<T> {...
///
/// // Not fitting, one possible example:
/// template <typename LongName>
/// requires C<LongName>
/// struct Foo {...
///
/// template <typename LongName>
/// requires C<LongName>
/// void bar(LongName ln) {
///
/// template <typename LongName>
/// void bar(LongName ln)
/// requires C<LongName> {
/// \endcode
RCPS_SingleLine,
};

/// \brief The position of the ``requires`` clause.
/// \version 15
RequiresClausePositionStyle RequiresClausePosition;

/// \brief The style if definition blocks should be separated.
enum SeparateDefinitionStyle {
/// Leave definition blocks as they are.
Expand Down Expand Up @@ -3889,8 +3983,8 @@ struct FormatStyle {
IndentGotoLabels == R.IndentGotoLabels &&
IndentPPDirectives == R.IndentPPDirectives &&
IndentExternBlock == R.IndentExternBlock &&
IndentRequires == R.IndentRequires && IndentWidth == R.IndentWidth &&
Language == R.Language &&
IndentRequiresClause == R.IndentRequiresClause &&
IndentWidth == R.IndentWidth && Language == R.Language &&
IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
JavaImportGroups == R.JavaImportGroups &&
JavaScriptQuotes == R.JavaScriptQuotes &&
Expand Down Expand Up @@ -3926,6 +4020,7 @@ struct FormatStyle {
RawStringFormats == R.RawStringFormats &&
ReferenceAlignment == R.ReferenceAlignment &&
RemoveBracesLLVM == R.RemoveBracesLLVM &&
RequiresClausePosition == R.RequiresClausePosition &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
SortIncludes == R.SortIncludes &&
Expand Down
32 changes: 16 additions & 16 deletions clang/lib/CodeGen/CGClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,22 +1649,22 @@ namespace {
}
};

static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
CharUnits::QuantityType PoisonSize) {
CodeGenFunction::SanitizerScope SanScope(&CGF);
// Pass in void pointer and size of region as arguments to runtime
// function
llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};

llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};

llvm::FunctionType *FnType =
llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
llvm::FunctionCallee Fn =
CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
CGF.EmitNounwindRuntimeCall(Fn, Args);
}
static void EmitSanitizerDtorCallback(CodeGenFunction &CGF, llvm::Value *Ptr,
CharUnits::QuantityType PoisonSize) {
CodeGenFunction::SanitizerScope SanScope(&CGF);
// Pass in void pointer and size of region as arguments to runtime
// function
llvm::Value *Args[] = {CGF.Builder.CreateBitCast(Ptr, CGF.VoidPtrTy),
llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)};

llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy};

llvm::FunctionType *FnType =
llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
llvm::FunctionCallee Fn =
CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
CGF.EmitNounwindRuntimeCall(Fn, Args);
}

class SanitizeDtorMembers final : public EHScopeStack::Cleanup {
const CXXDestructorDecl *Dtor;
Expand Down
43 changes: 26 additions & 17 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static Address createReferenceTemporary(CodeGenFunction &CGF,
GV->getValueType()->getPointerTo(
CGF.getContext().getTargetAddressSpace(LangAS::Default)));
// FIXME: Should we put the new global into a COMDAT?
return Address(C, alignment);
return Address(C, GV->getValueType(), alignment);
}
return CGF.CreateMemTemp(Ty, "ref.tmp", Alloca);
}
Expand Down Expand Up @@ -441,10 +441,10 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
ownership != Qualifiers::OCL_ExplicitNone) {
Address Object = createReferenceTemporary(*this, M, E);
if (auto *Var = dyn_cast<llvm::GlobalVariable>(Object.getPointer())) {
Object = Address(llvm::ConstantExpr::getBitCast(Var,
ConvertTypeForMem(E->getType())
->getPointerTo(Object.getAddressSpace())),
Object.getAlignment());
llvm::Type *Ty = ConvertTypeForMem(E->getType());
Object = Address(llvm::ConstantExpr::getBitCast(
Var, Ty->getPointerTo(Object.getAddressSpace())),
Ty, Object.getAlignment());

// createReferenceTemporary will promote the temporary to a global with a
// constant initializer if it can. It can only do this to a value of
Expand Down Expand Up @@ -499,9 +499,11 @@ EmitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *M) {
Address Object = createReferenceTemporary(*this, M, E, &Alloca);
if (auto *Var = dyn_cast<llvm::GlobalVariable>(
Object.getPointer()->stripPointerCasts())) {
llvm::Type *TemporaryType = ConvertTypeForMem(E->getType());
Object = Address(llvm::ConstantExpr::getBitCast(
cast<llvm::Constant>(Object.getPointer()),
ConvertTypeForMem(E->getType())->getPointerTo()),
TemporaryType->getPointerTo()),
TemporaryType,
Object.getAlignment());
// If the temporary is a global and has a constant initializer or is a
// constant temporary that we promoted to a global, we may have already
Expand Down Expand Up @@ -1208,9 +1210,10 @@ RValue CodeGenFunction::EmitUnsupportedRValue(const Expr *E,
LValue CodeGenFunction::EmitUnsupportedLValue(const Expr *E,
const char *Name) {
ErrorUnsupported(E, Name);
llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
return MakeAddrLValue(Address(llvm::UndefValue::get(Ty), CharUnits::One()),
E->getType());
llvm::Type *ElTy = ConvertType(E->getType());
llvm::Type *Ty = llvm::PointerType::getUnqual(ElTy);
return MakeAddrLValue(
Address(llvm::UndefValue::get(Ty), ElTy, CharUnits::One()), E->getType());
}

bool CodeGenFunction::IsWrappedCXXThis(const Expr *Obj) {
Expand Down Expand Up @@ -2741,8 +2744,10 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
LValue CapLVal =
EmitCapturedFieldLValue(*this, CapturedStmtInfo->lookup(VD),
CapturedStmtInfo->getContextValue());
Address LValueAddress = CapLVal.getAddress(*this);
CapLVal = MakeAddrLValue(
Address(CapLVal.getPointer(*this), getContext().getDeclAlign(VD)),
Address(LValueAddress.getPointer(), LValueAddress.getElementType(),
getContext().getDeclAlign(VD)),
CapLVal.getType(), LValueBaseInfo(AlignmentSource::Decl),
CapLVal.getTBAAInfo());
// Mark lvalue as nontemporal if the variable is marked as nontemporal
Expand Down Expand Up @@ -3431,7 +3436,8 @@ void CodeGenFunction::EmitCfiCheckFail() {
CfiCheckFailDataTy,
Builder.CreatePointerCast(Data, CfiCheckFailDataTy->getPointerTo(0)), 0,
0);
Address CheckKindAddr(V, getIntAlign());

Address CheckKindAddr(V, Int8Ty, getIntAlign());
llvm::Value *CheckKind = Builder.CreateLoad(CheckKindAddr);

llvm::Value *AllVtables = llvm::MetadataAsValue::get(
Expand Down Expand Up @@ -3817,7 +3823,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
llvm::Value *EltPtr =
emitArraySubscriptGEP(*this, Addr.getElementType(), Addr.getPointer(),
ScaledIdx, false, SignedIndices, E->getExprLoc());
Addr = Address(EltPtr, EltAlign);
Addr = Address(EltPtr, Addr.getElementType(), EltAlign);

// Cast back.
Addr = Builder.CreateBitCast(Addr, OrigBaseTy);
Expand Down Expand Up @@ -3917,7 +3923,8 @@ static Address emitOMPArraySectionBase(CodeGenFunction &CGF, const Expr *Base,
CGF.CGM.getNaturalTypeAlignment(ElTy, &TypeBaseInfo, &TypeTBAAInfo);
BaseInfo.mergeForCast(TypeBaseInfo);
TBAAInfo = CGF.CGM.mergeTBAAInfoForCast(TBAAInfo, TypeTBAAInfo);
return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress(CGF)), Align);
return Address(CGF.Builder.CreateLoad(BaseLVal.getAddress(CGF)),
CGF.ConvertTypeForMem(ElTy), Align);
}
return CGF.EmitPointerWithAlignment(Base, &BaseInfo, &TBAAInfo);
}
Expand Down Expand Up @@ -4374,7 +4381,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
// fields may leak the real address of dynamic object, which could result
// in miscompilation when leaked pointer would be compared.
auto *stripped = Builder.CreateStripInvariantGroup(addr.getPointer());
addr = Address(stripped, addr.getAlignment());
addr = Address(stripped, addr.getElementType(), addr.getAlignment());
}
}

Expand All @@ -4395,7 +4402,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
addr = Address(
Builder.CreatePreserveUnionAccessIndex(
addr.getPointer(), getDebugInfoFIndex(rec, field->getFieldIndex()), DbgInfo),
addr.getAlignment());
addr.getElementType(), addr.getAlignment());
}

if (FieldType->isReferenceType())
Expand Down Expand Up @@ -4779,7 +4786,8 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
*this, LV.getPointer(*this),
E->getSubExpr()->getType().getAddressSpace(),
E->getType().getAddressSpace(), ConvertType(DestTy));
return MakeAddrLValue(Address(V, LV.getAddress(*this).getAlignment()),
return MakeAddrLValue(Address(V, ConvertTypeForMem(E->getType()),
LV.getAddress(*this).getAlignment()),
E->getType(), LV.getBaseInfo(), LV.getTBAAInfo());
}
case CK_ObjCObjectLValueCast: {
Expand Down Expand Up @@ -5333,7 +5341,8 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, const CGCallee &OrigCallee
llvm::Value *Handle = Callee.getFunctionPointer();
auto *Cast =
Builder.CreateBitCast(Handle, Handle->getType()->getPointerTo());
auto *Stub = Builder.CreateLoad(Address(Cast, CGM.getPointerAlign()));
auto *Stub = Builder.CreateLoad(
Address(Cast, Handle->getType(), CGM.getPointerAlign()));
Callee.setFunctionPointer(Stub);
}
llvm::CallBase *CallOrInvoke = nullptr;
Expand Down
11 changes: 5 additions & 6 deletions clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,6 @@ void CodeGenModule::Release() {
"__amdgpu_device_library_preserve_asan_functions_ptr", nullptr,
llvm::GlobalVariable::NotThreadLocal);
addCompilerUsedGlobal(Var);
if (!getModule().getModuleFlag("amdgpu_hostcall")) {
getModule().addModuleFlag(llvm::Module::Override, "amdgpu_hostcall", 1);
}
}
// Emit amdgpu_code_object_version module flag, which is code object version
// times 100.
Expand Down Expand Up @@ -5673,9 +5670,11 @@ ConstantAddress CodeGenModule::GetAddrOfGlobalTemporary(
getModule(), Type, false, llvm::GlobalVariable::InternalLinkage,
nullptr);
}
return ConstantAddress(
InsertResult.first->second,
InsertResult.first->second->getType()->getPointerElementType(), Align);
return ConstantAddress(InsertResult.first->second,
llvm::cast<llvm::GlobalVariable>(
InsertResult.first->second->stripPointerCasts())
->getValueType(),
Align);
}

// FIXME: If an externally-visible declaration extends multiple temporaries,
Expand Down
80 changes: 65 additions & 15 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,32 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;

if (Current.NestingLevel == 0 && !Current.isTrailingComment()) {
// Always break after "template <...>" and leading annotations. This is only
// for cases where the entire line does not fit on a single line as a
// Always break after "template <...>"(*) and leading annotations. This is
// only for cases where the entire line does not fit on a single line as a
// different LineFormatter would be used otherwise.
if (Previous.ClosesTemplateDeclaration)
// *: Except when another option interferes with that, like concepts.
if (Previous.ClosesTemplateDeclaration) {
if (Current.is(tok::kw_concept)) {
switch (Style.BreakBeforeConceptDeclarations) {
case FormatStyle::BBCDS_Allowed:
break;
case FormatStyle::BBCDS_Always:
return true;
case FormatStyle::BBCDS_Never:
return false;
}
}
if (Current.is(TT_RequiresClause)) {
switch (Style.RequiresClausePosition) {
case FormatStyle::RCPS_SingleLine:
case FormatStyle::RCPS_WithPreceding:
return false;
default:
return true;
}
}
return Style.AlwaysBreakTemplateDeclarations != FormatStyle::BTDS_No;
}
if (Previous.is(TT_FunctionAnnotationRParen) &&
State.Line->Type != LT_PreprocessorDirective)
return true;
Expand Down Expand Up @@ -669,6 +690,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
!State.Stack.back().IsCSharpGenericTypeConstraint &&
Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) &&
Previous.isNot(TT_RequiresClause) &&
(Current.isNot(TT_LineComment) || Previous.is(BK_BracedInit))) {
State.Stack.back().Indent = State.Column + Spaces;
State.Stack.back().IsAligned = true;
Expand Down Expand Up @@ -880,7 +902,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
Previous.is(TT_BinaryOperator))
State.Stack.back().BreakBeforeParameter = false;
if (PreviousNonComment &&
PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
(PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) ||
PreviousNonComment->ClosesRequiresClause) &&
Current.NestingLevel == 0)
State.Stack.back().BreakBeforeParameter = false;
if (NextNonComment->is(tok::question) ||
Expand Down Expand Up @@ -927,13 +950,19 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
State.Stack[State.Stack.size() - 2].NestedBlockInlined) ||
(Style.Language == FormatStyle::LK_ObjC && Current.is(tok::r_brace) &&
State.Stack.size() > 1 && !Style.ObjCBreakBeforeNestedBlockParam);
// Do not force parameter break for statements with requires expressions.
NestedBlockSpecialCase =
NestedBlockSpecialCase ||
(Current.MatchingParen &&
Current.MatchingParen->is(TT_RequiresExpressionLBrace));
if (!NestedBlockSpecialCase)
for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)
State.Stack[i].BreakBeforeParameter = true;

if (PreviousNonComment &&
!PreviousNonComment->isOneOf(tok::comma, tok::colon, tok::semi) &&
(PreviousNonComment->isNot(TT_TemplateCloser) ||
((PreviousNonComment->isNot(TT_TemplateCloser) &&
!PreviousNonComment->ClosesRequiresClause) ||
Current.NestingLevel != 0) &&
!PreviousNonComment->isOneOf(
TT_BinaryOperator, TT_FunctionAnnotationRParen, TT_JavaAnnotation,
Expand Down Expand Up @@ -1096,8 +1125,20 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
}
if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0)
return State.Stack.back().VariablePos;
if (Current.is(TT_RequiresClause)) {
if (Style.IndentRequiresClause)
return State.Stack.back().Indent + Style.IndentWidth;
switch (Style.RequiresClausePosition) {
case FormatStyle::RCPS_OwnLine:
case FormatStyle::RCPS_WithFollowing:
return State.Stack.back().Indent;
default:
break;
}
}
if ((PreviousNonComment &&
(PreviousNonComment->ClosesTemplateDeclaration ||
PreviousNonComment->ClosesRequiresClause ||
PreviousNonComment->isOneOf(
TT_AttributeParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||
Expand Down Expand Up @@ -1288,6 +1329,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
State.Column + Current.ColumnWidth + 1;
if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
State.Stack.back().LastSpace = State.Column;
if (Current.is(TT_RequiresExpression))
State.Stack.back().NestedBlockIndent = State.Column;

// Insert scopes created by fake parenthesis.
const FormatToken *Previous = Current.getPreviousNonComment();
Expand All @@ -1298,8 +1341,8 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
// foo();
// bar();
// }, a, b, c);
if (Current.isNot(tok::comment) && Previous &&
Previous->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
if (Current.isNot(tok::comment) && !Current.ClosesRequiresClause &&
Previous && Previous->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
!Previous->is(TT_DictLiteral) && State.Stack.size() > 1 &&
!State.Stack.back().HasMultipleNestedBlocks) {
if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)
Expand Down Expand Up @@ -1359,14 +1402,15 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
const FormatToken *Previous = Current.getPreviousNonComment();

// Don't add extra indentation for the first fake parenthesis after
// 'return', assignments or opening <({[. The indentation for these cases
// is special cased.
// 'return', assignments, opening <({[, or requires clauses. The indentation
// for these cases is special cased.
bool SkipFirstExtraIndent =
(Previous && (Previous->opensScope() ||
Previous->isOneOf(tok::semi, tok::kw_return) ||
(Previous->getPrecedence() == prec::Assignment &&
Style.AlignOperands != FormatStyle::OAS_DontAlign) ||
Previous->is(TT_ObjCMethodExpr)));
Previous &&
(Previous->opensScope() ||
Previous->isOneOf(tok::semi, tok::kw_return, TT_RequiresClause) ||
(Previous->getPrecedence() == prec::Assignment &&
Style.AlignOperands != FormatStyle::OAS_DontAlign) ||
Previous->is(TT_ObjCMethodExpr));
for (const auto &PrecedenceLevel : llvm::reverse(Current.FakeLParens)) {
ParenState NewParenState = State.Stack.back();
NewParenState.Tok = nullptr;
Expand Down Expand Up @@ -1399,7 +1443,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,

if (Previous &&
(Previous->getPrecedence() == prec::Assignment ||
Previous->is(tok::kw_return) ||
Previous->isOneOf(tok::kw_return, TT_RequiresClause) ||
(PrecedenceLevel == prec::Conditional && Previous->is(tok::question) &&
Previous->is(TT_ConditionalExpr))) &&
!Newline) {
Expand Down Expand Up @@ -1457,6 +1501,12 @@ void ContinuationIndenter::moveStatePastFakeRParens(LineState &State) {
State.Stack.pop_back();
State.Stack.back().VariablePos = VariablePos;
}

if (State.NextToken->ClosesRequiresClause && Style.IndentRequiresClause) {
// Remove the indentation of the requires clauses (which is not in Indent,
// but in LastSpace).
State.Stack.back().LastSpace -= Style.IndentWidth;
}
}

void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
Expand Down
44 changes: 41 additions & 3 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,21 @@ struct ScalarEnumerationTraits<
}
};

template <>
struct ScalarEnumerationTraits<
FormatStyle::BreakBeforeConceptDeclarationsStyle> {
static void
enumeration(IO &IO, FormatStyle::BreakBeforeConceptDeclarationsStyle &Value) {
IO.enumCase(Value, "Never", FormatStyle::BBCDS_Never);
IO.enumCase(Value, "Allowed", FormatStyle::BBCDS_Allowed);
IO.enumCase(Value, "Always", FormatStyle::BBCDS_Always);

// For backward compatibility.
IO.enumCase(Value, "true", FormatStyle::BBCDS_Always);
IO.enumCase(Value, "false", FormatStyle::BBCDS_Allowed);
}
};

template <>
struct ScalarEnumerationTraits<FormatStyle::BreakConstructorInitializersStyle> {
static void
Expand Down Expand Up @@ -463,6 +478,17 @@ struct ScalarEnumerationTraits<FormatStyle::ReferenceAlignmentStyle> {
}
};

template <>
struct ScalarEnumerationTraits<FormatStyle::RequiresClausePositionStyle> {
static void enumeration(IO &IO,
FormatStyle::RequiresClausePositionStyle &Value) {
IO.enumCase(Value, "OwnLine", FormatStyle::RCPS_OwnLine);
IO.enumCase(Value, "WithPreceding", FormatStyle::RCPS_WithPreceding);
IO.enumCase(Value, "WithFollowing", FormatStyle::RCPS_WithFollowing);
IO.enumCase(Value, "SingleLine", FormatStyle::RCPS_SingleLine);
}
};

template <>
struct ScalarEnumerationTraits<FormatStyle::SpaceBeforeParensStyle> {
static void enumeration(IO &IO, FormatStyle::SpaceBeforeParensStyle &Value) {
Expand Down Expand Up @@ -565,6 +591,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment);
IO.mapOptional("IndentFunctionDeclarationAfterType",
Style.IndentWrappedFunctionNames);
IO.mapOptional("IndentRequires", Style.IndentRequiresClause);
IO.mapOptional("PointerBindsToType", Style.PointerAlignment);
IO.mapOptional("SpaceAfterControlStatementKeyword",
Style.SpaceBeforeParens);
Expand Down Expand Up @@ -737,7 +764,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
IO.mapOptional("IndentPPDirectives", Style.IndentPPDirectives);
IO.mapOptional("IndentExternBlock", Style.IndentExternBlock);
IO.mapOptional("IndentRequires", Style.IndentRequires);
IO.mapOptional("IndentRequiresClause", Style.IndentRequiresClause);
IO.mapOptional("IndentWidth", Style.IndentWidth);
IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
Expand Down Expand Up @@ -782,6 +809,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
IO.mapOptional("ReflowComments", Style.ReflowComments);
IO.mapOptional("RemoveBracesLLVM", Style.RemoveBracesLLVM);
IO.mapOptional("RequiresClausePosition", Style.RequiresClausePosition);
IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
IO.mapOptional("SortIncludes", Style.SortIncludes);
Expand Down Expand Up @@ -1130,7 +1158,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BinPackArguments = true;
LLVMStyle.BinPackParameters = true;
LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
LLVMStyle.BreakBeforeConceptDeclarations = true;
LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
LLVMStyle.BreakBeforeTernaryOperators = true;
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
LLVMStyle.BraceWrapping = {/*AfterCaseLabel=*/false,
Expand Down Expand Up @@ -1188,7 +1216,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.IndentCaseBlocks = false;
LLVMStyle.IndentGotoLabels = true;
LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
LLVMStyle.IndentRequires = false;
LLVMStyle.IndentRequiresClause = true;
LLVMStyle.IndentWrappedFunctionNames = false;
LLVMStyle.IndentWidth = 2;
LLVMStyle.PPIndentWidth = -1;
Expand All @@ -1207,6 +1235,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
LLVMStyle.RequiresClausePosition = FormatStyle::RCPS_OwnLine;
LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
LLVMStyle.ShortNamespaceLines = 1;
LLVMStyle.SpacesBeforeTrailingComments = 1;
Expand Down Expand Up @@ -3048,6 +3077,15 @@ reformat(const FormatStyle &Style, StringRef Code,
FormatStyle Expanded = Style;
expandPresetsBraceWrapping(Expanded);
expandPresetsSpaceBeforeParens(Expanded);
switch (Expanded.RequiresClausePosition) {
case FormatStyle::RCPS_SingleLine:
case FormatStyle::RCPS_WithPreceding:
Expanded.IndentRequiresClause = false;
break;
default:
break;
}

if (Expanded.DisableFormat)
return {tooling::Replacements(), 0};
if (isLikelyXml(Code))
Expand Down
16 changes: 13 additions & 3 deletions clang/lib/Format/FormatToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ namespace format {
TYPE(BinaryOperator) \
TYPE(BitFieldColon) \
TYPE(BlockComment) \
TYPE(BracedListLBrace) \
TYPE(CastRParen) \
TYPE(CompoundRequirementLBrace) \
TYPE(ConditionalExpr) \
TYPE(ConflictAlternative) \
TYPE(ConflictEnd) \
TYPE(ConflictStart) \
TYPE(ConstraintJunctions) \
TYPE(CtorInitializerColon) \
TYPE(CtorInitializerComma) \
TYPE(DesignatedInitializerLSquare) \
Expand Down Expand Up @@ -98,6 +99,11 @@ namespace format {
TYPE(RangeBasedForLoopColon) \
TYPE(RecordLBrace) \
TYPE(RegexLiteral) \
TYPE(RequiresClause) \
TYPE(RequiresClauseInARequiresExpression) \
TYPE(RequiresExpression) \
TYPE(RequiresExpressionLBrace) \
TYPE(RequiresExpressionLParen) \
TYPE(SelectorName) \
TYPE(StartOfName) \
TYPE(StatementAttributeLikeMacro) \
Expand Down Expand Up @@ -245,8 +251,9 @@ struct FormatToken {
CanBreakBefore(false), ClosesTemplateDeclaration(false),
StartsBinaryExpression(false), EndsBinaryExpression(false),
PartOfMultiVariableDeclStmt(false), ContinuesLineCommentSection(false),
Finalized(false), BlockKind(BK_Unknown), Decision(FD_Unformatted),
PackingKind(PPK_Inconclusive), Type(TT_Unknown) {}
Finalized(false), ClosesRequiresClause(false), BlockKind(BK_Unknown),
Decision(FD_Unformatted), PackingKind(PPK_Inconclusive),
Type(TT_Unknown) {}

/// The \c Token.
Token Tok;
Expand Down Expand Up @@ -312,6 +319,9 @@ struct FormatToken {
/// changes.
unsigned Finalized : 1;

/// \c true if this is the last token within requires clause.
unsigned ClosesRequiresClause : 1;

private:
/// Contains the kind of block if this token is a brace.
unsigned BlockKind : 2;
Expand Down
95 changes: 74 additions & 21 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ class AnnotatingParser {
return false;
if (Line.MustBeDeclaration && Contexts.size() == 1 &&
!Contexts.back().IsExpression && !Line.startsWith(TT_ObjCProperty) &&
!Tok->is(TT_TypeDeclarationParen) &&
!Tok->isOneOf(TT_TypeDeclarationParen, TT_RequiresExpressionLParen) &&
(!Tok->Previous || !Tok->Previous->isOneOf(tok::kw___attribute,
TT_LeadingJavaAnnotation)))
Line.MightBeFunctionDecl = true;
Expand Down Expand Up @@ -1152,6 +1152,10 @@ class AnnotatingParser {
parseCSharpGenericTypeConstraint();
}
break;
case tok::arrow:
if (Tok->Previous && Tok->Previous->is(tok::kw_noexcept))
Tok->setType(TT_TrailingReturnArrow);
break;
default:
break;
}
Expand Down Expand Up @@ -1412,9 +1416,12 @@ class AnnotatingParser {
TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_FatArrow,
TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral,
TT_UntouchableMacroFunc, TT_ConstraintJunctions,
TT_StatementAttributeLikeMacro, TT_FunctionLikeOrFreestandingMacro,
TT_RecordLBrace))
TT_UntouchableMacroFunc, TT_StatementAttributeLikeMacro,
TT_FunctionLikeOrFreestandingMacro, TT_RecordLBrace,
TT_RequiresClause, TT_RequiresClauseInARequiresExpression,
TT_RequiresExpression, TT_RequiresExpressionLParen,
TT_RequiresExpressionLBrace, TT_BinaryOperator,
TT_CompoundRequirementLBrace, TT_BracedListLBrace))
CurrentToken->setType(TT_Unknown);
CurrentToken->Role.reset();
CurrentToken->MatchingParen = nullptr;
Expand Down Expand Up @@ -1609,7 +1616,8 @@ class AnnotatingParser {
PriorLeadingIdentifier = PriorLeadingIdentifier->Previous;

return (PriorLeadingIdentifier &&
PriorLeadingIdentifier->is(TT_TemplateCloser) &&
(PriorLeadingIdentifier->is(TT_TemplateCloser) ||
PriorLeadingIdentifier->ClosesRequiresClause) &&
LeadingIdentifier->TokenText == Current.Next->TokenText);
}
}
Expand Down Expand Up @@ -1826,6 +1834,9 @@ class AnnotatingParser {
if (!PreviousNotConst)
return false;

if (PreviousNotConst->ClosesRequiresClause)
return false;

bool IsPPKeyword = PreviousNotConst->is(tok::identifier) &&
PreviousNotConst->Previous &&
PreviousNotConst->Previous->is(tok::hash);
Expand Down Expand Up @@ -2164,7 +2175,7 @@ class ExpressionParser {
public:
ExpressionParser(const FormatStyle &Style, const AdditionalKeywords &Keywords,
AnnotatedLine &Line)
: Style(Style), Keywords(Keywords), Current(Line.First) {}
: Style(Style), Keywords(Keywords), Line(Line), Current(Line.First) {}

/// Parse expressions with the given operator precedence.
void parse(int Precedence = 0) {
Expand Down Expand Up @@ -2219,7 +2230,11 @@ class ExpressionParser {
break;

// Consume scopes: (), [], <> and {}
if (Current->opensScope()) {
// In addition to that we handle require clauses as scope, so that the
// constraints in that are correctly indented.
if (Current->opensScope() ||
Current->isOneOf(TT_RequiresClause,
TT_RequiresClauseInARequiresExpression)) {
// In fragment of a JavaScript template string can look like '}..${' and
// thus close a scope and open a new one at the same time.
while (Current && (!Current->closesScope() || Current->opensScope())) {
Expand All @@ -2241,12 +2256,26 @@ class ExpressionParser {
}

if (LatestOperator && (Current || Precedence > 0)) {
// LatestOperator->LastOperator = true;
// The requires clauses do not neccessarily end in a semicolon or a brace,
// but just go over to struct/class or a function declaration, we need to
// intervene so that the fake right paren is inserted correctly.
auto End =
(Start->Previous &&
Start->Previous->isOneOf(TT_RequiresClause,
TT_RequiresClauseInARequiresExpression))
? [this](){
auto Ret = Current ? Current : Line.Last;
while (!Ret->ClosesRequiresClause && Ret->Previous)
Ret = Ret->Previous;
return Ret;
}()
: nullptr;

if (Precedence == PrecedenceArrowAndPeriod) {
// Call expressions don't have a binary operator precedence.
addFakeParenthesis(Start, prec::Unknown);
addFakeParenthesis(Start, prec::Unknown, End);
} else {
addFakeParenthesis(Start, prec::Level(Precedence));
addFakeParenthesis(Start, prec::Level(Precedence), End);
}
}
}
Expand Down Expand Up @@ -2295,17 +2324,17 @@ class ExpressionParser {
return -1;
}

void addFakeParenthesis(FormatToken *Start, prec::Level Precedence) {
void addFakeParenthesis(FormatToken *Start, prec::Level Precedence,
FormatToken *End = nullptr) {
Start->FakeLParens.push_back(Precedence);
if (Precedence > prec::Unknown)
Start->StartsBinaryExpression = true;
if (Current) {
FormatToken *Previous = Current->Previous;
while (Previous->is(tok::comment) && Previous->Previous)
Previous = Previous->Previous;
++Previous->FakeRParens;
if (!End && Current)
End = Current->getPreviousNonComment();
if (End) {
++End->FakeRParens;
if (Precedence > prec::Unknown)
Previous->EndsBinaryExpression = true;
End->EndsBinaryExpression = true;
}
}

Expand Down Expand Up @@ -2350,6 +2379,7 @@ class ExpressionParser {

const FormatStyle &Style;
const AdditionalKeywords &Keywords;
const AnnotatedLine &Line;
FormatToken *Current;
};

Expand Down Expand Up @@ -2920,6 +2950,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
}
if (Left.ClosesTemplateDeclaration)
return Style.PenaltyBreakTemplateDeclaration;
if (Left.ClosesRequiresClause)
return 0;
if (Left.is(TT_ConditionalExpr))
return prec::Conditional;
prec::Level Level = Left.getPrecedence();
Expand Down Expand Up @@ -2987,9 +3019,6 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
if (Left.isOneOf(tok::kw_co_await, tok::kw_co_yield, tok::kw_co_return) &&
Right.isNot(tok::semi))
return true;
// requires clause Concept1<T> && Concept2<T>
if (Left.is(TT_ConstraintJunctions) && Right.is(tok::identifier))
return true;

if (Left.is(tok::l_paren) || Right.is(tok::r_paren))
return (Right.is(TT_CastRParen) ||
Expand Down Expand Up @@ -3892,16 +3921,34 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
Right.Next->is(tok::string_literal))
return true;
if (Right.is(TT_RequiresClause)) {
switch (Style.RequiresClausePosition) {
case FormatStyle::RCPS_OwnLine:
case FormatStyle::RCPS_WithFollowing:
return true;
default:
break;
}
}
// Can break after template<> declaration
if (Left.ClosesTemplateDeclaration && Left.MatchingParen &&
Left.MatchingParen->NestingLevel == 0) {
// Put concepts on the next line e.g.
// template<typename T>
// concept ...
if (Right.is(tok::kw_concept))
return Style.BreakBeforeConceptDeclarations;
return Style.BreakBeforeConceptDeclarations == FormatStyle::BBCDS_Always;
return (Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_Yes);
}
if (Left.ClosesRequiresClause) {
switch (Style.RequiresClausePosition) {
case FormatStyle::RCPS_OwnLine:
case FormatStyle::RCPS_WithPreceding:
return true;
default:
break;
}
}
if (Style.PackConstructorInitializers == FormatStyle::PCIS_Never) {
if (Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeColon &&
(Left.is(TT_CtorInitializerComma) || Right.is(TT_CtorInitializerColon)))
Expand Down Expand Up @@ -4296,8 +4343,14 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
if (Left.is(tok::r_paren) && Line.Type == LT_ObjCProperty)
return true;
if (Right.is(tok::kw_concept))
return Style.BreakBeforeConceptDeclarations != FormatStyle::BBCDS_Never;
if (Right.is(TT_RequiresClause))
return true;
if (Left.ClosesTemplateDeclaration || Left.is(TT_FunctionAnnotationRParen))
return true;
if (Left.ClosesRequiresClause)
return true;
if (Right.isOneOf(TT_RangeBasedForLoopColon, TT_OverloadedOperatorLParen,
TT_OverloadedOperator))
return false;
Expand Down
372 changes: 262 additions & 110 deletions clang/lib/Format/UnwrappedLineParser.cpp

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions clang/lib/Format/UnwrappedLineParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ class UnwrappedLineParser {
void reset();
void parseFile();
bool precededByCommentOrPPDirective() const;
bool parseLevel(bool HasOpeningBrace, IfStmtKind *IfKind = nullptr);
bool parseLevel(bool HasOpeningBrace, bool CanContainBracedList,
IfStmtKind *IfKind = nullptr,
TokenType NextLBracesType = TT_Unknown);
IfStmtKind parseBlock(bool MustBeDeclaration = false, unsigned AddLevels = 1u,
bool MunchSemi = true,
bool UnindentWhitesmithsBraces = false);
void parseChildBlock();
bool UnindentWhitesmithsBraces = false,
bool CanContainBracedList = true,
TokenType NextLBracesType = TT_Unknown);
void parseChildBlock(bool CanContainBracedList = true,
TokenType NextLBracesType = TT_Unknown);
void parsePPDirective();
void parsePPDefine();
void parsePPIf(bool IfDef);
Expand All @@ -106,11 +111,12 @@ class UnwrappedLineParser {
void parsePPUnknown();
void readTokenWithJavaScriptASI();
void parseStructuralElement(IfStmtKind *IfKind = nullptr,
bool IsTopLevel = false);
bool IsTopLevel = false,
TokenType NextLBracesType = TT_Unknown);
bool tryToParseBracedList();
bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,
tok::TokenKind ClosingBraceKind = tok::r_brace);
void parseParens();
void parseParens(TokenType AmpAmpTokenType = TT_Unknown);
void parseSquare(bool LambdaIntroducer = false);
void keepAncestorBraces();
FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
Expand All @@ -127,9 +133,9 @@ class UnwrappedLineParser {
bool parseEnum();
bool parseStructLike();
void parseConcept();
void parseRequires();
void parseRequiresExpression(unsigned int OriginalLevel);
void parseConstraintExpression(unsigned int OriginalLevel);
void parseRequiresClause();
void parseRequiresExpression();
void parseConstraintExpression();
void parseJavaEnumBody();
// Parses a record (aka class) as a top level element. If ParseAsExpr is true,
// parses the record as a child block, i.e. if the class declaration is an
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
if (SrcType->isIntegralOrEnumerationType()) {
// [expr.static.cast]p10 If the enumeration type has a fixed underlying
// type, the value is first converted to that type by integral conversion
const EnumType *Enum = DestType->getAs<EnumType>();
const EnumType *Enum = DestType->castAs<EnumType>();
Kind = Enum->getDecl()->isFixed() &&
Enum->getDecl()->getIntegerType()->isBooleanType()
? CK_IntegralToBoolean
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11310,7 +11310,7 @@ void CheckFreeArgumentsCast(Sema &S, const std::string &CalleeName,
/// Alerts the user that they are attempting to free a non-malloc'd object.
void Sema::CheckFreeArguments(const CallExpr *E) {
const std::string CalleeName =
dyn_cast<FunctionDecl>(E->getCalleeDecl())->getQualifiedNameAsString();
cast<FunctionDecl>(E->getCalleeDecl())->getQualifiedNameAsString();

{ // Prefer something that doesn't involve a cast to make things simpler.
const Expr *Arg = E->getArg(0)->IgnoreParenCasts();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaCoroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ static void checkNoThrow(Sema &S, const Stmt *E,
QualType::DestructionKind::DK_cxx_destructor) {
const auto *T =
cast<RecordType>(ReturnType.getCanonicalType().getTypePtr());
checkDeclNoexcept(dyn_cast<CXXRecordDecl>(T->getDecl())->getDestructor(),
checkDeclNoexcept(cast<CXXRecordDecl>(T->getDecl())->getDestructor(),
/*IsDtor=*/true);
}
} else
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/CFContainers-invalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CFArrayRef CFArrayCreate(CFAllocatorRef);
CFDictionaryRef CFDictionaryCreate(CFAllocatorRef);
CFSetRef CFSetCreate(CFAllocatorRef);

void testNoCrash() {
void testNoCrash(void) {
(void)CFArrayCreate(kCFAllocatorDefault);
(void)CFDictionaryCreate(kCFAllocatorDefault);
(void)CFSetCreate(kCFAllocatorDefault);
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Analysis/CGColorSpace.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ extern CGColorSpaceRef CGColorSpaceCreateDeviceRGB(void);
extern CGColorSpaceRef CGColorSpaceRetain(CGColorSpaceRef space);
extern void CGColorSpaceRelease(CGColorSpaceRef space);

void f() {
void f(void) {
CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB(); // expected-warning{{leak}}
CGColorSpaceRetain(X);
}

void fb() {
void fb(void) {
CGColorSpaceRef X = CGColorSpaceCreateDeviceRGB();
CGColorSpaceRetain(X);
CGColorSpaceRelease(X);
Expand Down
28 changes: 14 additions & 14 deletions clang/test/Analysis/Checkers/RunLoopAutoreleaseLeakChecker.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

#ifndef EXTRA

void just_runloop() { // No warning: no statements in between
void just_runloop(void) { // No warning: no statements in between
@autoreleasepool {
[[NSRunLoop mainRunLoop] run]; // no-warning
}
}

void just_xpcmain() { // No warning: no statements in between
void just_xpcmain(void) { // No warning: no statements in between
@autoreleasepool {
xpc_main(); // no-warning
}
}

void runloop_init_before() { // Warning: object created before the loop.
void runloop_init_before(void) { // Warning: object created before the loop.
@autoreleasepool {
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
(void) object;
[[NSRunLoop mainRunLoop] run];
}
}

void runloop_init_before_separate_pool() { // No warning: separate autorelease pool.
void runloop_init_before_separate_pool(void) { // No warning: separate autorelease pool.
@autoreleasepool {
NSObject *object;
@autoreleasepool {
Expand All @@ -46,15 +46,15 @@ void runloop_init_before_separate_pool() { // No warning: separate autorelease p
}
}

void xpcmain_init_before() { // Warning: object created before the loop.
void xpcmain_init_before(void) { // Warning: object created before the loop.
@autoreleasepool {
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of xpc_main may never get released; consider moving them to a separate autorelease pool}}
(void) object;
xpc_main();
}
}

void runloop_init_before_two_objects() { // Warning: object created before the loop.
void runloop_init_before_two_objects(void) { // Warning: object created before the loop.
@autoreleasepool {
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
NSObject *object2 = [[NSObject alloc] init]; // no-warning, warning on the first one is enough.
Expand All @@ -64,21 +64,21 @@ void runloop_init_before_two_objects() { // Warning: object created before the l
}
}

void runloop_no_autoreleasepool() {
void runloop_no_autoreleasepool(void) {
NSObject *object = [[NSObject alloc] init]; // no-warning
(void)object;
[[NSRunLoop mainRunLoop] run];
}

void runloop_init_after() { // No warning: objects created after the loop
void runloop_init_after(void) { // No warning: objects created after the loop
@autoreleasepool {
[[NSRunLoop mainRunLoop] run];
NSObject *object = [[NSObject alloc] init]; // no-warning
(void) object;
}
}

void no_crash_on_empty_children() {
void no_crash_on_empty_children(void) {
@autoreleasepool {
for (;;) {}
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
Expand All @@ -90,7 +90,7 @@ void no_crash_on_empty_children() {
#endif

#ifdef AP1
int main() {
int main(void) {
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool of last resort followed by the launch of main run loop may never get released; consider moving them to a separate autorelease pool}}
(void) object;
[[NSRunLoop mainRunLoop] run];
Expand All @@ -100,7 +100,7 @@ int main() {

#ifdef AP2
// expected-no-diagnostics
int main() {
int main(void) {
NSObject *object = [[NSObject alloc] init]; // no-warning
(void) object;
@autoreleasepool {
Expand All @@ -112,7 +112,7 @@ int main() {

#ifdef AP3
// expected-no-diagnostics
int main() {
int main(void) {
[[NSRunLoop mainRunLoop] run];
NSObject *object = [[NSObject alloc] init]; // no-warning
(void) object;
Expand All @@ -121,7 +121,7 @@ int main() {
#endif

#ifdef AP4
int main() {
int main(void) {
NSObject *object = [[NSObject alloc] init]; // expected-warning{{Temporary objects allocated in the autorelease pool of last resort followed by the launch of xpc_main may never get released; consider moving them to a separate autorelease pool}}
(void) object;
xpc_main();
Expand All @@ -148,7 +148,7 @@ @interface I

#define CFSTR __builtin___CFStringMakeConstantString

int main() {
int main(void) {
I *i;
@autoreleasepool {
NSString *s1 = (__bridge_transfer NSString *)processString(0, 0);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/DeallocUseAfterFreeErrors.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.cocoa.SuperDealloc,debug.ExprInspection -analyzer-output=text -verify %s

void clang_analyzer_warnIfReached();
void clang_analyzer_warnIfReached(void);

#define nil ((id)0)

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/Inputs/ctu-other.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int g(struct S *ctx) {
// Test that asm import does not fail.
// TODO: Support the GNU extension asm keyword as well.
// Example using the GNU extension: asm("mov $42, %0" : "=r"(res));
int inlineAsm() {
int inlineAsm(void) {
int res;
__asm__("mov $42, %0"
: "=r"(res));
Expand Down
16 changes: 8 additions & 8 deletions clang/test/Analysis/NSContainers.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,33 @@ + (NSNull *)null;
@end

// NSMutableArray API
void testNilArgNSMutableArray1() {
void testNilArgNSMutableArray1(void) {
NSMutableArray *marray = [[NSMutableArray alloc] init];
[marray addObject:0]; // expected-warning {{Argument to 'NSMutableArray' method 'addObject:' cannot be nil}}
}

void testNilArgNSMutableArray2() {
void testNilArgNSMutableArray2(void) {
NSMutableArray *marray = [[NSMutableArray alloc] init];
[marray insertObject:0 atIndex:1]; // expected-warning {{Argument to 'NSMutableArray' method 'insertObject:atIndex:' cannot be nil}}
}

void testNilArgNSMutableArray3() {
void testNilArgNSMutableArray3(void) {
NSMutableArray *marray = [[NSMutableArray alloc] init];
[marray replaceObjectAtIndex:1 withObject:0]; // expected-warning {{Argument to 'NSMutableArray' method 'replaceObjectAtIndex:withObject:' cannot be nil}}
}

void testNilArgNSMutableArray4() {
void testNilArgNSMutableArray4(void) {
NSMutableArray *marray = [[NSMutableArray alloc] init];
[marray setObject:0 atIndexedSubscript:1]; // expected-warning {{Argument to 'NSMutableArray' method 'setObject:atIndexedSubscript:' cannot be nil}}
}

void testNilArgNSMutableArray5() {
void testNilArgNSMutableArray5(void) {
NSMutableArray *marray = [[NSMutableArray alloc] init];
marray[1] = 0; // expected-warning {{Array element cannot be nil}}
}

// NSArray API
void testNilArgNSArray1() {
void testNilArgNSArray1(void) {
NSArray *array = [[NSArray alloc] init];
NSArray *copyArray = [array arrayByAddingObject:0]; // expected-warning {{Argument to 'NSArray' method 'arrayByAddingObject:' cannot be nil}}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ void idc2(id x) {
if (!x)
return;
}
Foo *retNil() {
Foo *retNil(void) {
return 0;
}

Expand Down Expand Up @@ -282,7 +282,7 @@ void testCountAwareNSOrderedSet(NSOrderedSet *containers, int *validptr) {
}
}

void testLiteralsNonNil() {
void testLiteralsNonNil(void) {
clang_analyzer_eval(!!@[]); // expected-warning{{TRUE}}
clang_analyzer_eval(!!@{}); // expected-warning{{TRUE}}
}
Expand Down
24 changes: 12 additions & 12 deletions clang/test/Analysis/NSString.m
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ NSComparisonResult f5(NSString* s, NSStringCompareOptions op, NSRange R) {
return s4;
}

NSMutableArray* f8() {
NSMutableArray* f8(void) {

NSString* s = [[NSString alloc] init];
NSMutableArray* a = [[NSMutableArray alloc] initWithCapacity:2];
Expand All @@ -143,15 +143,15 @@ NSComparisonResult f5(NSString* s, NSStringCompareOptions op, NSRange R) {
return a;
}

void f9() {
void f9(void) {

NSString* s = [[NSString alloc] init];
NSString* q = s;
[s release];
[q release]; // expected-warning {{used after it is released}}
}

NSString* f10() {
NSString* f10(void) {
static NSString* s = 0;
if (!s) s = [[NSString alloc] init];
return s; // no-warning
Expand All @@ -172,7 +172,7 @@ void f9() {
// Test case for passing a tracked object by-reference to a function we
// don't understand.
void unknown_function_f12(NSString** s);
void f12() {
void f12(void) {
NSString *string = [[NSString alloc] init];
unknown_function_f12(&string); // no-warning
}
Expand Down Expand Up @@ -275,7 +275,7 @@ + (id)sharedInstance {
}
@end

id testSharedClassFromFunction() {
id testSharedClassFromFunction(void) {
return [[SharedClass alloc] _init]; // no-warning
}

Expand All @@ -300,7 +300,7 @@ extern BOOL objc_atomicCompareAndSwapPtr(id predicate, id replacement, volatile
}
#endif

void testOSCompareAndSwap() {
void testOSCompareAndSwap(void) {
NSString *old = 0;
NSString *s = [[NSString alloc] init]; // no-warning
if (!OSAtomicCompareAndSwapPtr(0, s, (void**) &old))
Expand All @@ -309,7 +309,7 @@ void testOSCompareAndSwap() {
[old release];
}

void testOSCompareAndSwapXXBarrier_local() {
void testOSCompareAndSwapXXBarrier_local(void) {
NSString *old = 0;
NSString *s = [[NSString alloc] init]; // no-warning
if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) &old))
Expand All @@ -318,7 +318,7 @@ void testOSCompareAndSwapXXBarrier_local() {
[old release];
}

void testOSCompareAndSwapXXBarrier_local_no_direct_release() {
void testOSCompareAndSwapXXBarrier_local_no_direct_release(void) {
NSString *old = 0;
NSString *s = [[NSString alloc] init]; // no-warning
if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) &old))
Expand All @@ -333,7 +333,7 @@ int testOSCompareAndSwapXXBarrier_id(Class myclass, id xclass) {
return 0;
}

void test_objc_atomicCompareAndSwap_local() {
void test_objc_atomicCompareAndSwap_local(void) {
NSString *old = 0;
NSString *s = [[NSString alloc] init]; // no-warning
if (!objc_atomicCompareAndSwapPtr(0, s, &old))
Expand All @@ -342,7 +342,7 @@ void test_objc_atomicCompareAndSwap_local() {
[old release];
}

void test_objc_atomicCompareAndSwap_local_no_direct_release() {
void test_objc_atomicCompareAndSwap_local_no_direct_release(void) {
NSString *old = 0;
NSString *s = [[NSString alloc] init]; // no-warning
if (!objc_atomicCompareAndSwapPtr(0, s, &old))
Expand All @@ -369,13 +369,13 @@ void test_objc_atomicCompareAndSwap_parameter_no_direct_release(NSString **old)


// Test stringWithFormat (<rdar://problem/6815234>)
void test_stringWithFormat() {
void test_stringWithFormat(void) {
NSString *string = [[NSString stringWithFormat:@"%ld", (long) 100] retain];
[string release];
[string release]; // expected-warning{{Incorrect decrement of the reference count}}
}

// Test isTrackedObjectType().
// Test isTrackedObjectType(void).
typedef NSString* WonkyTypedef;
@interface TestIsTracked
+ (WonkyTypedef)newString;
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Analysis/NSWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ - (void)orderFrontRegardless;

// Test cases.

void f1() {
void f1(void) {
NSWindow *window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0,0,100,100)
styleMask:NSTitledWindowMask|NSClosableWindowMask
Expand All @@ -54,7 +54,7 @@ void f1() {
[window orderFrontRegardless]; // no-warning
}

void f2() {
void f2(void) {
NSWindow *window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0,0,100,100)
styleMask:NSTitledWindowMask|NSClosableWindowMask
Expand All @@ -65,7 +65,7 @@ void f2() {
[window orderFrontRegardless]; // no-warning
}

void f2b() {
void f2b(void) {
// FIXME: NSWindow doesn't own itself until it is displayed.
NSWindow *window = [[NSWindow alloc] // no-warning
initWithContentRect:NSMakeRect(0,0,100,100)
Expand All @@ -80,7 +80,7 @@ void f2b() {
}


void f3() {
void f3(void) {
// FIXME: For now we don't track NSWindow.
NSWindow *window = [NSWindow alloc]; // expected-warning{{never read}}
}
8 changes: 4 additions & 4 deletions clang/test/Analysis/NoReturn.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ + (void) doesNotReturn __attribute__((analyzer_noreturn));
- (void) alsoDoesNotReturn __attribute__((analyzer_noreturn));
@end

void test_rdar11634353() {
void test_rdar11634353(void) {
[Radar11634353 doesNotReturn];
int *p = 0;
*p = 0xDEADBEEF; // no-warning
Expand All @@ -107,7 +107,7 @@ void test_rdar11634352_instance(Radar11634353 *o) {
*p = 0xDEADBEEF; // no-warning
}

void test_rdar11634353_positive() {
void test_rdar11634353_positive(void) {
int *p = 0;
*p = 0xDEADBEEF; // expected-warning {{null pointer}}
}
Expand All @@ -126,7 +126,7 @@ void PR11959(int *p) {
// Test that hard-coded Microsoft _wassert name is recognized as a noreturn
#define assert(_Expression) (void)( (!!(_Expression)) || (_wassert(#_Expression, __FILE__, __LINE__), 0) )
extern void _wassert(const char * _Message, const char *_File, unsigned _Line);
void test_wassert() {
void test_wassert(void) {
assert(0);
int *p = 0;
*p = 0xDEADBEEF; // no-warning
Expand All @@ -137,7 +137,7 @@ void test_wassert() {
#define assert(_Expression) ((_Expression) ? (void)0 : __assert2(0, 0, 0, 0));
extern void __assert2(const char *, int, const char *, const char *);
extern void _wassert(const char * _Message, const char *_File, unsigned _Line);
void test___assert2() {
void test___assert2(void) {
assert(0);
int *p = 0;
*p = 0xDEADBEEF; // no-warning
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Analysis/OSAtomic_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int OSAtomicCompareAndSwapPtrBarrier() {
// but we should trust our BodyFarm instead.
}

int *invalidSLocOnRedecl() {
int *invalidSLocOnRedecl(void) {
// Was crashing when trying to throw a report about returning an uninitialized
// value to the caller. FIXME: We should probably still throw that report,
// something like "The "compare" part of CompareAndSwap depends on an
Expand All @@ -17,7 +17,7 @@ int *invalidSLocOnRedecl() {
return b;
}

void testThatItActuallyWorks() {
void testThatItActuallyWorks(void) {
void *x = 0;
int res = OSAtomicCompareAndSwapPtrBarrier(0, &x, &x);
clang_analyzer_eval(res); // expected-warning{{TRUE}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/UserNullabilityAnnotations.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)method2:(int *)x {
int *_Nonnull Value;
} NestedNonnullMember;

NestedNonnullMember *foo();
NestedNonnullMember *foo(void);

void f1(NestedNonnullMember *Root) {
NestedNonnullMember *Grandson = Root->Child->Child;
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Analysis/_Bool-increment-decrement.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection -verify -std=c11 -Dbool=_Bool -Dtrue=1 -Dfalse=0 %s
extern void clang_analyzer_eval(bool);

void test__Bool_value() {
void test__Bool_value(void) {
{
bool b = true;
clang_analyzer_eval(b == 1); // expected-warning{{TRUE}}
Expand Down Expand Up @@ -36,7 +36,7 @@ void test__Bool_value() {
}
}

void test__Bool_increment() {
void test__Bool_increment(void) {
{
bool b = true;
b++;
Expand Down Expand Up @@ -87,7 +87,7 @@ void test__Bool_increment() {
}
}

void test__Bool_decrement() {
void test__Bool_decrement(void) {
{
bool b = true;
b--;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/analyzer-display-progress.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Inputs/system-header-simulator-objc.h"

static void f() {}
static void f(void) {}

@interface I: NSObject
-(void)instanceMethod:(int)arg1 with:(int)arg2;
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Analysis/analyzer-stats.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks -analyzer-max-loop 4 %s

int foo();
int foo(void);

int test() { // expected-warning-re{{test -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: no | Empty WorkList: yes}}
int test(void) { // expected-warning-re{{test -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: no | Empty WorkList: yes}}
int a = 1;
a = 34 / 12;

Expand All @@ -14,15 +14,15 @@ int test() { // expected-warning-re{{test -> Total CFGBlocks: {{[0-9]+}} | Unrea
}


int sink() // expected-warning-re{{sink -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 1 | Exhausted Block: yes | Empty WorkList: yes}}
int sink(void) // expected-warning-re{{sink -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 1 | Exhausted Block: yes | Empty WorkList: yes}}
{
for (int i = 0; i < 10; ++i) // expected-warning {{(sink): The analyzer generated a sink at this point}}
++i;

return 0;
}

int emptyConditionLoop() // expected-warning-re{{emptyConditionLoop -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: yes | Empty WorkList: yes}}
int emptyConditionLoop(void) // expected-warning-re{{emptyConditionLoop -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: yes | Empty WorkList: yes}}
{
int num = 1;
for (;;)
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Analysis/arc-zero-init.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
@interface SomeClass
@end

void simpleStrongPointerValue() {
void simpleStrongPointerValue(void) {
SomeClass *x;
if (x) {}
#if !__has_feature(objc_arc)
// expected-warning@-2{{Branch condition evaluates to a garbage value}}
#endif
}

void simpleArray() {
void simpleArray(void) {
SomeClass *vlaArray[5];

if (vlaArray[0]) {}
Expand All @@ -25,7 +25,7 @@ void simpleArray() {
#endif
}

void variableLengthArray() {
void variableLengthArray(void) {
int count = 1;
SomeClass * vlaArray[count];

Expand All @@ -35,7 +35,7 @@ void variableLengthArray() {
#endif
}

void variableLengthArrayWithExplicitStrongAttribute() {
void variableLengthArrayWithExplicitStrongAttribute(void) {
int count = 1;
__attribute__((objc_ownership(strong))) SomeClass * vlaArray[count];

Expand Down
22 changes: 11 additions & 11 deletions clang/test/Analysis/array-struct-region.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void clang_analyzer_eval(int);

int string_literal_init() {
int string_literal_init(void) {
char a[] = "abc";
char b[2] = "abc"; // expected-warning{{too long}}
char c[5] = "abc";
Expand Down Expand Up @@ -42,7 +42,7 @@ void nested_compound_literals_float(float rad) {
}


void struct_as_array() {
void struct_as_array(void) {
struct simple { int x; int y; };
struct simple a;
struct simple *p = &a;
Expand All @@ -60,14 +60,14 @@ void struct_as_array() {
// PR13264 / <rdar://problem/11802440>
struct point { int x; int y; };
struct circle { struct point o; int r; };
struct circle get_circle() {
struct circle get_circle(void) {
struct circle result;
result.r = 5;
result.o = (struct point){0, 0};
return result;
}

void struct_in_struct() {
void struct_in_struct(void) {
struct circle c;
c = get_circle();
// This used to think c.r was undefined because c.o is a LazyCompoundVal.
Expand All @@ -77,22 +77,22 @@ void struct_in_struct() {
// We also test with floats because we don't model floats right now,
// and the original bug report used a float.
struct circle_f { struct point o; float r; };
struct circle_f get_circle_f() {
struct circle_f get_circle_f(void) {
struct circle_f result;
result.r = 5.0;
result.o = (struct point){0, 0};
return result;
}

float struct_in_struct_f() {
float struct_in_struct_f(void) {
struct circle_f c;
c = get_circle_f();

return c.r; // no-warning
}


int randomInt();
int randomInt(void);

int testSymbolicInvalidation(int index) {
int vals[10];
Expand Down Expand Up @@ -122,7 +122,7 @@ typedef struct {
int x, y, z;
} S;

S makeS();
S makeS(void);

int testSymbolicInvalidationStruct(int index) {
S vals[10];
Expand Down Expand Up @@ -183,7 +183,7 @@ int testConcreteInvalidationDoubleStruct(int index) {
}


int testNonOverlappingStructFieldsSimple() {
int testNonOverlappingStructFieldsSimple(void) {
S val;

val.x = 1;
Expand Down Expand Up @@ -277,7 +277,7 @@ typedef struct {
int length;
} ShortStringWrapper;

void testArrayStructCopy() {
void testArrayStructCopy(void) {
ShortString s = { "abc" };
ShortString s2 = s;
ShortString s3 = s2;
Expand All @@ -294,7 +294,7 @@ void testArrayStructCopy() {
clang_analyzer_eval(s4.data[2] == 'c'); // expected-warning{{TRUE}}
}

void testArrayStructCopyNested() {
void testArrayStructCopyNested(void) {
ShortString s = { "abc" };
ShortString s2 = s;

Expand Down
12 changes: 6 additions & 6 deletions clang/test/Analysis/array-struct-region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ bool operator ~(const struct S &s) { return (&s) != &s; }


#ifdef INLINE
struct S getS() {
struct S getS(void) {
struct S s = { 42 };
return s;
}
#else
struct S getS();
struct S getS(void);
#endif


void testAssignment() {
void testAssignment(void) {
struct S s = getS();

if (s.field != 42) return;
Expand All @@ -78,7 +78,7 @@ void testAssignment() {
}


void testImmediateUse() {
void testImmediateUse(void) {
int x = getS().field;

if (x != 42) return;
Expand All @@ -105,12 +105,12 @@ int getAssignedField(struct S s) {
return s.field;
}

void testArgument() {
void testArgument(void) {
clang_analyzer_eval(getConstrainedField(getS()) == 42); // expected-warning{{TRUE}}
clang_analyzer_eval(getAssignedField(getS()) == 42); // expected-warning{{TRUE}}
}

void testImmediateUseParens() {
void testImmediateUseParens(void) {
int x = ((getS())).field;

if (x != 42) return;
Expand Down
32 changes: 16 additions & 16 deletions clang/test/Analysis/array-struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ void f(void) {

// StringLiteral in lvalue context and pointer to array type.
// p: ElementRegion, q: StringRegion
void f2() {
void f2(void) {
char *p = "/usr/local";
char (*q)[4];
q = &"abc";
}

// Typedef'ed struct definition.
void f3() {
void f3(void) {
STYPE s;
}

// Initialize array with InitExprList.
void f4() {
void f4(void) {
int a[] = { 1, 2, 3};
int b[3] = { 1, 2 };
struct s c[] = {{1,{1}}};
}

// Struct variable in lvalue context.
// Assign UnknownVal to the whole struct.
void f5() {
void f5(void) {
struct s data;
g1(&data);
}

// AllocaRegion test.
void f6() {
void f6(void) {
char *p;
p = __builtin_alloca(10);
g(p);
Expand All @@ -70,30 +70,30 @@ struct s2;
void g2(struct s2 *p);

// Incomplete struct pointer used as function argument.
void f7() {
void f7(void) {
struct s2 *p = __builtin_alloca(10);
g2(p);
}

// sizeof() is unsigned while -1 is signed in array index.
void f8() {
void f8(void) {
int a[10];
a[sizeof(a)/sizeof(int) - 1] = 1; // no-warning
}

// Initialization of struct array elements.
void f9() {
void f9(void) {
struct s a[10];
}

// Initializing array with string literal.
void f10() {
void f10(void) {
char a1[4] = "abc";
char a3[6] = "abc";
}

// Retrieve the default value of element/field region.
void f11() {
void f11(void) {
struct s a;
g1(&a);
if (a.data == 0) // no-warning
Expand Down Expand Up @@ -129,25 +129,25 @@ struct s3 {
static struct s3 opt;

// Test if the embedded array is retrieved correctly.
void f14() {
void f14(void) {
struct s3 my_opt = opt;
}

void bar(int*);

struct s3 gets3() {
struct s3 gets3(void) {
struct s3 s;
return s;
}

void accessArrayFieldNoCrash() {
void accessArrayFieldNoCrash(void) {
bar(gets3().a);
bar((gets3().a));
bar(((gets3().a)));
}

// Test if the array is correctly invalidated.
void f15() {
void f15(void) {
int a[10];
bar(a);
if (a[1]) // no-warning
Expand All @@ -167,7 +167,7 @@ void f16(struct s3 *p) {
void inv(struct s1 *);

// Invalidate the struct field.
void f17() {
void f17(void) {
struct s1 t;
int x;
inv(&t);
Expand All @@ -177,7 +177,7 @@ void f17() {

void read(char*);

void f18() {
void f18(void) {
char *q;
char *p = (char *) __builtin_alloca(10);
read(p);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/assume-controlled-environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

char *getenv(const char *name);

void foo() {
void foo(void) {
char *p = getenv("FOO"); // untrusted-env-warning {{tainted}}
(void)p; // untrusted-env-warning {{tainted}}
}
6 changes: 3 additions & 3 deletions clang/test/Analysis/blocks-no-inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void clang_analyzer_eval(int);

void testInvalidation() {
void testInvalidation(void) {
__block int i = 0;
^{
++i;
Expand All @@ -15,7 +15,7 @@ void testInvalidation() {


const int globalConstant = 1;
void testCapturedConstants() {
void testCapturedConstants(void) {
const int localConstant = 2;
static const int staticConstant = 3;

Expand All @@ -28,7 +28,7 @@ void testCapturedConstants() {

typedef const int constInt;
constInt anotherGlobalConstant = 1;
void testCapturedConstantsTypedef() {
void testCapturedConstantsTypedef(void) {
constInt localConstant = 2;
static constInt staticConstant = 3;

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/blocks-nrvo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ typedef struct {
int x;
} S;

void foo() {
void foo(void) {
^{
S s;
return s; // no-crash
Expand Down
34 changes: 17 additions & 17 deletions clang/test/Analysis/blocks.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,27 @@ void test1(NSString *format, ...) {

// test2 - Test that captured variables that are uninitialized are flagged
// as such.
void test2() {
void test2(void) {
static int y = 0;
int x;
^{ y = x + 1; }(); // expected-warning{{Variable 'x' is uninitialized when captured by block}}
}

void test2_b() {
void test2_b(void) {
static int y = 0;
__block int x;
^{ y = x + 1; }(); // expected-warning {{left operand of '+' is a garbage value}}
}

void test2_c() {
void test2_c(void) {
typedef void (^myblock)(void);
myblock f = ^() { f(); }; // expected-warning{{Variable 'f' is uninitialized when captured by block}}
myblock f = ^(void) { f(); }; // expected-warning{{Variable 'f' is uninitialized when captured by block}}
}


void testMessaging() {
void testMessaging(void) {
// <rdar://problem/12119814>
[[^(){} copy] release];
[[^(void){} copy] release];
}


Expand Down Expand Up @@ -133,16 +133,16 @@ - (void)test {
}
@end

void testReturnVariousSignatures() {
(void)^int(){
void testReturnVariousSignatures(void) {
(void)^int(void){
return 42;
}();

(void)^int{
return 42;
}();

(void)^(){
(void)^(void){
return 42;
}();

Expand Down Expand Up @@ -173,39 +173,39 @@ void blockCapturesItselfInTheLoop(int x, int m) {
void takeNonnullBlock(void (^)(void)) __attribute__((nonnull));
void takeNonnullIntBlock(int (^)(void)) __attribute__((nonnull));

void testCallContainingWithSignature1()
void testCallContainingWithSignature1(void)
{
takeNonnullBlock(^{
static const char str[] = "Lost connection to sharingd";
testCallContainingWithSignature1();
});
}

void testCallContainingWithSignature2()
void testCallContainingWithSignature2(void)
{
takeNonnullBlock(^void{
static const char str[] = "Lost connection to sharingd";
testCallContainingWithSignature2();
});
}

void testCallContainingWithSignature3()
void testCallContainingWithSignature3(void)
{
takeNonnullBlock(^void(){
takeNonnullBlock(^void(void){
static const char str[] = "Lost connection to sharingd";
testCallContainingWithSignature3();
});
}

void testCallContainingWithSignature4()
void testCallContainingWithSignature4(void)
{
takeNonnullBlock(^void(void){
static const char str[] = "Lost connection to sharingd";
testCallContainingWithSignature4();
});
}

void testCallContainingWithSignature5()
void testCallContainingWithSignature5(void)
{
takeNonnullIntBlock(^{
static const char str[] = "Lost connection to sharingd";
Expand Down Expand Up @@ -240,13 +240,13 @@ -(void)foo; {
// The incorrect block variable initialization below is a hard compile-time
// error in C++.
#if !defined(__cplusplus)
void call_block_with_fewer_arguments() {
void call_block_with_fewer_arguments(void) {
void (^b)() = ^(int a) { };
b(); // expected-warning {{Block taking 1 argument is called with fewer (0)}}
}
#endif

int getBlockFlags() {
int getBlockFlags(void) {
int x = 0;
return ((struct Block_layout *)^{ (void)x; })->flags; // no-warning
}
22 changes: 11 additions & 11 deletions clang/test/Analysis/bsd-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ size_t strlcat(char *dst, const char *src, size_t n);
size_t strlen(const char *s);
void clang_analyzer_eval(int);

void f1() {
void f1(void) {
char overlap[] = "123456789";
strlcpy(overlap, overlap + 1, 3); // expected-warning{{Arguments must not be overlapping buffers}}
}

void f2() {
void f2(void) {
char buf[5];
size_t len;
len = strlcpy(buf, "abcd", sizeof(buf)); // expected-no-warning
Expand All @@ -26,33 +26,33 @@ void f2() {
clang_analyzer_eval(len == 8); // expected-warning{{TRUE}}
}

void f3() {
void f3(void) {
char dst[2];
const char *src = "abdef";
strlcpy(dst, src, 5); // expected-warning{{String copy function overflows the destination buffer}}
}

void f4() {
void f4(void) {
strlcpy(NULL, "abcdef", 6); // expected-warning{{Null pointer passed as 1st argument to string copy function}}
}

void f5() {
void f5(void) {
strlcat(NULL, "abcdef", 6); // expected-warning{{Null pointer passed as 1st argument to string concatenation function}}
}

void f6() {
void f6(void) {
char buf[8];
strlcpy(buf, "abc", 3);
size_t len = strlcat(buf, "defg", 4);
clang_analyzer_eval(len == 7); // expected-warning{{TRUE}}
}

int f7() {
int f7(void) {
char buf[8];
return strlcpy(buf, "1234567", 0); // no-crash
}

void f8(){
void f8(void){
char buf[5];
size_t len;

Expand Down Expand Up @@ -116,7 +116,7 @@ void f9(int unknown_size, char* unknown_src, char* unknown_dst){
// expected-warning@-1 {{String concatenation function overflows the destination buffer}}
}

void f10(){
void f10(void){
char buf[8];
size_t len;

Expand All @@ -126,7 +126,7 @@ void f10(){
// expected-warning@-1 {{String concatenation function overflows the destination buffer}}
}

void f11() {
void f11(void) {
//test for Bug 41729
char a[256], b[256];
strlcpy(a, "world", sizeof(a));
Expand All @@ -135,7 +135,7 @@ void f11() {
}

int a, b;
void unknown_val_crash() {
void unknown_val_crash(void) {
// We're unable to evaluate the integer-to-pointer cast.
strlcat(&b, a, 0); // no-crash
}
82 changes: 41 additions & 41 deletions clang/test/Analysis/bstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void *memcpy(void *restrict s1, const void *restrict s2, size_t n);
#endif /* VARIANT */


void memcpy0 () {
void memcpy0 (void) {
char src[] = {1, 2, 3, 4};
char dst[4] = {0};

Expand All @@ -84,14 +84,14 @@ void memcpy0 () {
clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
}

void memcpy1 () {
void memcpy1 (void) {
char src[] = {1, 2, 3, 4};
char dst[10];

memcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}}
}

void memcpy2 () {
void memcpy2 (void) {
char src[] = {1, 2, 3, 4};
char dst[1];

Expand All @@ -101,21 +101,21 @@ void memcpy2 () {
#endif
}

void memcpy3 () {
void memcpy3 (void) {
char src[] = {1, 2, 3, 4};
char dst[3];

memcpy(dst+1, src+2, 2); // no-warning
}

void memcpy4 () {
void memcpy4 (void) {
char src[] = {1, 2, 3, 4};
char dst[10];

memcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}}
}

void memcpy5() {
void memcpy5(void) {
char src[] = {1, 2, 3, 4};
char dst[3];

Expand All @@ -125,43 +125,43 @@ void memcpy5() {
#endif
}

void memcpy6() {
void memcpy6(void) {
int a[4] = {0};
memcpy(a, a, 8); // expected-warning{{overlapping}}
}

void memcpy7() {
void memcpy7(void) {
int a[4] = {0};
memcpy(a+2, a+1, 8); // expected-warning{{overlapping}}
}

void memcpy8() {
void memcpy8(void) {
int a[4] = {0};
memcpy(a+1, a+2, 8); // expected-warning{{overlapping}}
}

void memcpy9() {
void memcpy9(void) {
int a[4] = {0};
memcpy(a+2, a+1, 4); // no-warning
memcpy(a+1, a+2, 4); // no-warning
}

void memcpy10() {
void memcpy10(void) {
char a[4] = {0};
memcpy(0, a, 4); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
}

void memcpy11() {
void memcpy11(void) {
char a[4] = {0};
memcpy(a, 0, 4); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
}

void memcpy12() {
void memcpy12(void) {
char a[4] = {0};
memcpy(0, a, 0); // no-warning
}

void memcpy13() {
void memcpy13(void) {
char a[4] = {0};
memcpy(a, 0, 0); // no-warning
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void *mempcpy(void *restrict s1, const void *restrict s2, size_t n);
#endif /* VARIANT */


void mempcpy0 () {
void mempcpy0 (void) {
char src[] = {1, 2, 3, 4};
char dst[5] = {0};

Expand All @@ -210,14 +210,14 @@ void mempcpy0 () {
clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
}

void mempcpy1 () {
void mempcpy1 (void) {
char src[] = {1, 2, 3, 4};
char dst[10];

mempcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}}
}

void mempcpy2 () {
void mempcpy2 (void) {
char src[] = {1, 2, 3, 4};
char dst[1];

Expand All @@ -227,21 +227,21 @@ void mempcpy2 () {
#endif
}

void mempcpy3 () {
void mempcpy3 (void) {
char src[] = {1, 2, 3, 4};
char dst[3];

mempcpy(dst+1, src+2, 2); // no-warning
}

void mempcpy4 () {
void mempcpy4 (void) {
char src[] = {1, 2, 3, 4};
char dst[10];

mempcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}}
}

void mempcpy5() {
void mempcpy5(void) {
char src[] = {1, 2, 3, 4};
char dst[3];

Expand All @@ -251,48 +251,48 @@ void mempcpy5() {
#endif
}

void mempcpy6() {
void mempcpy6(void) {
int a[4] = {0};
mempcpy(a, a, 8); // expected-warning{{overlapping}}
}

void mempcpy7() {
void mempcpy7(void) {
int a[4] = {0};
mempcpy(a+2, a+1, 8); // expected-warning{{overlapping}}
}

void mempcpy8() {
void mempcpy8(void) {
int a[4] = {0};
mempcpy(a+1, a+2, 8); // expected-warning{{overlapping}}
}

void mempcpy9() {
void mempcpy9(void) {
int a[4] = {0};
mempcpy(a+2, a+1, 4); // no-warning
mempcpy(a+1, a+2, 4); // no-warning
}

void mempcpy10() {
void mempcpy10(void) {
char a[4] = {0};
mempcpy(0, a, 4); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
}

void mempcpy11() {
void mempcpy11(void) {
char a[4] = {0};
mempcpy(a, 0, 4); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
}

void mempcpy12() {
void mempcpy12(void) {
char a[4] = {0};
mempcpy(0, a, 0); // no-warning
}

void mempcpy13() {
void mempcpy13(void) {
char a[4] = {0};
mempcpy(a, 0, 0); // no-warning
}

void mempcpy14() {
void mempcpy14(void) {
int src[] = {1, 2, 3, 4};
int dst[5] = {0};
int *p;
Expand All @@ -307,7 +307,7 @@ struct st {
int j;
};

void mempcpy15() {
void mempcpy15(void) {
struct st s1 = {0};
struct st s2;
struct st *p1;
Expand All @@ -319,7 +319,7 @@ void mempcpy15() {
clang_analyzer_eval(p1 == p2); // expected-warning{{TRUE}}
}

void mempcpy16() {
void mempcpy16(void) {
struct st s1[10] = {{0}};
struct st s2[10];
struct st *p1;
Expand Down Expand Up @@ -362,7 +362,7 @@ void *memmove(void *s1, const void *s2, size_t n);
#endif /* VARIANT */


void memmove0 () {
void memmove0 (void) {
char src[] = {1, 2, 3, 4};
char dst[4] = {0};

Expand All @@ -375,14 +375,14 @@ void memmove0 () {
clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
}

void memmove1 () {
void memmove1 (void) {
char src[] = {1, 2, 3, 4};
char dst[10];

memmove(dst, src, 5); // expected-warning{{out-of-bound}}
}

void memmove2 () {
void memmove2 (void) {
char src[] = {1, 2, 3, 4};
char dst[1];

Expand Down Expand Up @@ -410,28 +410,28 @@ int memcmp(const void *s1, const void *s2, size_t n);
#endif /* VARIANT */


void memcmp0 () {
void memcmp0 (void) {
char a[] = {1, 2, 3, 4};
char b[4] = { 0 };

memcmp(a, b, 4); // no-warning
}

void memcmp1 () {
void memcmp1 (void) {
char a[] = {1, 2, 3, 4};
char b[10] = { 0 };

memcmp(a, b, 5); // expected-warning{{out-of-bound}}
}

void memcmp2 () {
void memcmp2 (void) {
char a[] = {1, 2, 3, 4};
char b[1] = { 0 };

memcmp(a, b, 4); // expected-warning{{out-of-bound}}
}

void memcmp3 () {
void memcmp3 (void) {
char a[] = {1, 2, 3, 4};

clang_analyzer_eval(memcmp(a, a, 4) == 0); // expected-warning{{TRUE}}
Expand Down Expand Up @@ -483,7 +483,7 @@ int memcmp8(char *a, size_t n) {
void bcopy(/*const*/ void *s1, void *s2, size_t n);


void bcopy0 () {
void bcopy0 (void) {
char src[] = {1, 2, 3, 4};
char dst[4] = {0};

Expand All @@ -494,14 +494,14 @@ void bcopy0 () {
clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
}

void bcopy1 () {
void bcopy1 (void) {
char src[] = {1, 2, 3, 4};
char dst[10];

bcopy(src, dst, 5); // expected-warning{{out-of-bound}}
}

void bcopy2 () {
void bcopy2 (void) {
char src[] = {1, 2, 3, 4};
char dst[1];

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/bug_hash_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ - (void)method:(int)arg param:(int)arg2 {
@end


void testBlocks() {
void testBlocks(void) {
int x = 5;
^{
clang_analyzer_hashDump(x); // expected-warning {{debug.ExprInspection$$29$clang_analyzer_hashDump(x);$Category}}
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Analysis/c11lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void bad5(void) {
mtx_unlock(&mtx1); // expected-warning {{This lock has already been unlocked}}
}

void bad6() {
void bad6(void) {
mtx_init(&mtx1, 0);
if (mtx_trylock(&mtx1) != thrd_success)
mtx_unlock(&mtx1); // expected-warning {{This lock has already been unlocked}}
Expand All @@ -65,23 +65,23 @@ void bad7(void) {
mtx_unlock(&mtx2);
}

void good() {
void good(void) {
mtx_t mtx;
mtx_init(&mtx, 0);
mtx_lock(&mtx);
mtx_unlock(&mtx);
mtx_destroy(&mtx);
}

void good2() {
void good2(void) {
mtx_t mtx;
mtx_init(&mtx, 0);
if (mtx_trylock(&mtx) == thrd_success)
mtx_unlock(&mtx);
mtx_destroy(&mtx);
}

void good3() {
void good3(void) {
mtx_t mtx;
mtx_init(&mtx, 0);
if (mtx_timedlock(&mtx, 0) == thrd_success)
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/call-and-message.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// no-pointee-no-diagnostics

void doStuff_pointerToConstInt(const int *u){};
void pointee_uninit() {
void pointee_uninit(void) {
int i;
int *p = &i;
doStuff_pointerToConstInt(p); // expected-warning{{1st function call argument is a pointer to uninitialized value [core.CallAndMessage]}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/call-and-message.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)addObject:(id)object;
// Test cases.
//===----------------------------------------------------------------------===//

unsigned f1() {
unsigned f1(void) {
NSString *aString;
return [aString length]; // expected-warning {{Receiver in message expression is an uninitialized value [core.CallAndMessage]}}
}
Expand Down
20 changes: 10 additions & 10 deletions clang/test/Analysis/casts.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int foo (int* p) {
return 0;
}

void castsToBool() {
void castsToBool(void) {
clang_analyzer_eval(0); // expected-warning{{FALSE}}
clang_analyzer_eval(0U); // expected-warning{{FALSE}}
clang_analyzer_eval((void *)0); // expected-warning{{FALSE}}
Expand Down Expand Up @@ -128,7 +128,7 @@ void locAsIntegerCasts(void *p) {
clang_analyzer_eval(++x < 10); // no-crash // expected-warning{{UNKNOWN}}
}

void multiDimensionalArrayPointerCasts() {
void multiDimensionalArrayPointerCasts(void) {
static int x[10][10];
int *y1 = &(x[3][5]);
char *z = ((char *) y1) + 2;
Expand All @@ -154,23 +154,23 @@ void multiDimensionalArrayPointerCasts() {
clang_analyzer_eval(*((char *)y1) == *((char *) y3)); // expected-warning{{TRUE}}
}

void *getVoidPtr();
void *getVoidPtr(void);

void testCastVoidPtrToIntPtrThroughIntTypedAssignment() {
void testCastVoidPtrToIntPtrThroughIntTypedAssignment(void) {
int *x;
(*((int *)(&x))) = (int)getVoidPtr();
*x = 1; // no-crash
}

void testCastUIntPtrToIntPtrThroughIntTypedAssignment() {
void testCastUIntPtrToIntPtrThroughIntTypedAssignment(void) {
unsigned u;
int *x;
(*((int *)(&x))) = (int)&u;
*x = 1;
clang_analyzer_eval(u == 1); // expected-warning{{TRUE}}
}

void testCastVoidPtrToIntPtrThroughUIntTypedAssignment() {
void testCastVoidPtrToIntPtrThroughUIntTypedAssignment(void) {
int *x;
(*((int *)(&x))) = (int)(unsigned *)getVoidPtr();
*x = 1; // no-crash
Expand All @@ -187,7 +187,7 @@ void testLocNonLocSymbolRemainder(int a, int *b) {
}
}

void testSwitchWithSizeofs() {
void testSwitchWithSizeofs(void) {
switch (sizeof(char) == 1) { // expected-warning{{switch condition has boolean value}}
case sizeof(char):; // no-crash
}
Expand Down Expand Up @@ -219,8 +219,8 @@ void test_VectorSplat_cast(long x) {
#ifdef EAGERLY_ASSUME

int globalA;
extern int globalFunc();
void no_crash_on_symsym_cast_to_long() {
extern int globalFunc(void);
void no_crash_on_symsym_cast_to_long(void) {
char c = globalFunc() - 5;
c == 0;
globalA -= c;
Expand All @@ -240,7 +240,7 @@ char no_crash_SymbolCast_of_float_type_aux(int *p) {
return *p;
}

void no_crash_SymbolCast_of_float_type() {
void no_crash_SymbolCast_of_float_type(void) {
extern float x;
char (*f)() = no_crash_SymbolCast_of_float_type_aux;
f(&x);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/casts.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ @interface RDR10087620 : NSObject {


// PR16690
_Bool testLocAsIntegerToBool() {
_Bool testLocAsIntegerToBool(void) {
return (long long)&testLocAsIntegerToBool;
}
34 changes: 17 additions & 17 deletions clang/test/Analysis/cert/env34-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ char *asctime(const tm *timeptr);

int strcmp(const char*, const char*);
extern void foo(char *e);
extern char* bar();
extern char* bar(void);


void getenv_test1() {
void getenv_test1(void) {
char *p;

p = getenv("VAR");
Expand All @@ -31,7 +31,7 @@ void getenv_test1() {
*p; // no-warning, getenv result was assigned to the same pointer
}

void getenv_test2() {
void getenv_test2(void) {
char *p, *p2;

p = getenv("VAR");
Expand All @@ -46,7 +46,7 @@ void getenv_test2() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test3() {
void getenv_test3(void) {
char *p, *p2, *p3;

p = getenv("VAR");
Expand All @@ -64,7 +64,7 @@ void getenv_test3() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test4() {
void getenv_test4(void) {
char *p, *p2, *p3;

p = getenv("VAR");
Expand All @@ -78,7 +78,7 @@ void getenv_test4() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test5() {
void getenv_test5(void) {
char *p, *p2, *p3;

p = getenv("VAR");
Expand All @@ -92,7 +92,7 @@ void getenv_test5() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test6() {
void getenv_test6(void) {
char *p, *p2;
p = getenv("VAR");
*p; // no-warning
Expand Down Expand Up @@ -120,7 +120,7 @@ void getenv_test6() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test7() {
void getenv_test7(void) {
char *p, *p2;
p = getenv("VAR");
// expected-note@-1{{previous function call was here}}
Expand All @@ -134,7 +134,7 @@ void getenv_test7() {
// expected-note@-2{{use of invalidated pointer 'p' in a function call}}
}

void getenv_test8() {
void getenv_test8(void) {
static const char *array[] = {
0,
0,
Expand All @@ -159,15 +159,15 @@ void getenv_test8() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test9() {
void getenv_test9(void) {
char *p, *p2;
p = getenv("something");
p = bar();
p2 = getenv("something");
*p; // no-warning: p does not point to getenv anymore
}

void getenv_test10() {
void getenv_test10(void) {
strcmp(getenv("VAR1"), getenv("VAR2"));
// expected-note@-1{{'getenv' call may invalidate the the result of the previous 'getenv'}}
// expected-note@-2{{previous function call was here}}
Expand All @@ -181,7 +181,7 @@ void dereference_pointer(char* a) {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void getenv_test11() {
void getenv_test11(void) {
char *p = getenv("VAR");
// expected-note@-1{{previous function call was here}}

Expand Down Expand Up @@ -212,7 +212,7 @@ void getenv_test12(int flag1, int flag2) {
}
}

void setlocale_test1() {
void setlocale_test1(void) {
char *p, *p2;
p = setlocale(0, "VAR");
*p; // no-warning
Expand Down Expand Up @@ -250,7 +250,7 @@ void setlocale_test2(int flag) {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void strerror_test1() {
void strerror_test1(void) {
char *p, *p2;

p = strerror(0);
Expand Down Expand Up @@ -298,7 +298,7 @@ void strerror_test2(int errno) {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void asctime_test() {
void asctime_test(void) {
const tm *t;
const tm *tt;

Expand All @@ -312,7 +312,7 @@ void asctime_test() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void localeconv_test1() {
void localeconv_test1(void) {
lconv *lc1 = localeconv();
// expected-note@-1{{previous function call was here}}
lconv *lc2 = localeconv();
Expand All @@ -323,7 +323,7 @@ void localeconv_test1() {
// expected-note@-2{{dereferencing an invalid pointer}}
}

void localeconv_test2() {
void localeconv_test2(void) {
// TODO: false negative
lconv *lc1 = localeconv();
lconv *lc2 = localeconv();
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void checkWrap(int i) {
// CHECK-NEXT: 4: asm ("" : "=r" ([B1.3]));
// CHECK-NEXT: 5: arg
// CHECK-NEXT: 6: asm ("" : "=r" ([B1.5]));
void checkGCCAsmRValueOutput() {
void checkGCCAsmRValueOutput(void) {
int arg;
__asm__("" : "=r"((int)arg)); // rvalue output operand
__asm__("" : "=r"(arg)); // lvalue output operand
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/class-object-state-dump.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// expected-no-diagnostics

void clang_analyzer_printState();
void clang_analyzer_printState(void);

@interface NSObject {
}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/compound-literals.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void foo(void) {
}

// check that we propagate info through compound literal regions
void bar() {
void bar(void) {
int *integers = (int[]){1, 2, 3};
clang_analyzer_eval(integers[0] == 1); // expected-warning{{TRUE}}
clang_analyzer_eval(integers[1] == 2); // expected-warning{{TRUE}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/concrete-address.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -analyzer-store=region -verify %s
// expected-no-diagnostics

void foo() {
void foo(void) {
int *p = (int*) 0x10000; // Should not crash here.
*p = 3;
}
2 changes: 1 addition & 1 deletion clang/test/Analysis/constant-folding.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void testBitwiseRules(unsigned int a, int b, int c) {
}
}

unsigned reset();
unsigned reset(void);

void testCombinedSources(unsigned a, unsigned b) {
if (b >= 10 && (a | b) <= 30) {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/constraint-assignor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: -analyzer-checker=debug.ExprInspection \
// RUN: -verify

void clang_analyzer_warnIfReached();
void clang_analyzer_warnIfReached(void);
void clang_analyzer_eval(int);

void rem_constant_rhs_ne_zero(int x, int y) {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/conversion-tracking-notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
unsigned char U8;
signed char S8;

void track_assign() {
void track_assign(void) {
unsigned long L = 1000; // expected-note {{'L' initialized to 1000}}
int I = -1; // expected-note {{'I' initialized to -1}}
U8 *= L; // expected-warning {{Loss of precision in implicit conversion}}
Expand Down
36 changes: 18 additions & 18 deletions clang/test/Analysis/conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ void assign(unsigned U, signed S) {
S8 = U; // no-warning
}

void addAssign() {
void addAssign(void) {
unsigned long L = 1000;
int I = -100;
U8 += L; // expected-warning {{Loss of precision in implicit conversion}}
L += I; // no-warning
}

void subAssign() {
void subAssign(void) {
unsigned long L = 1000;
int I = -100;
U8 -= L; // expected-warning {{Loss of precision in implicit conversion}}
L -= I; // no-warning
}

void mulAssign() {
void mulAssign(void) {
unsigned long L = 1000;
int I = -1;
U8 *= L; // expected-warning {{Loss of precision in implicit conversion}}
Expand All @@ -40,42 +40,42 @@ void mulAssign() {
L *= I; // no-warning
}

void divAssign() {
void divAssign(void) {
unsigned long L = 1000;
int I = -1;
U8 /= L; // no-warning
L /= I; // expected-warning {{Loss of sign in implicit conversion}}
}

void remAssign() {
void remAssign(void) {
unsigned long L = 1000;
int I = -1;
U8 %= L; // no-warning
L %= I; // expected-warning {{Loss of sign in implicit conversion}}
}

void andAssign() {
void andAssign(void) {
unsigned long L = 1000;
int I = -1;
U8 &= L; // no-warning
L &= I; // expected-warning {{Loss of sign in implicit conversion}}
}

void orAssign() {
void orAssign(void) {
unsigned long L = 1000;
int I = -1;
U8 |= L; // expected-warning {{Loss of precision in implicit conversion}}
L |= I; // expected-warning {{Loss of sign in implicit conversion}}
}

void xorAssign() {
void xorAssign(void) {
unsigned long L = 1000;
int I = -1;
U8 ^= L; // expected-warning {{Loss of precision in implicit conversion}}
L ^= I; // expected-warning {{Loss of sign in implicit conversion}}
}

void init1() {
void init1(void) {
long long A = 1LL << 60;
short X = A; // expected-warning {{Loss of precision in implicit conversion}}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ void division(unsigned U, signed S) {
void f(unsigned x) {}
void g(unsigned x) {}

void functioncall1() {
void functioncall1(void) {
long x = -1;
int y = 0;
f(x); // expected-warning {{Loss of sign in implicit conversion}}
Expand Down Expand Up @@ -145,11 +145,11 @@ void dontwarn3(int X) {

// don't warn for macros
#define DOSTUFF ({ unsigned X = 1000; U8 = X; })
void dontwarn4() {
void dontwarn4(void) {
DOSTUFF;
}

void dontwarn5() {
void dontwarn5(void) {
unsigned char c1 = 'A';
c1 = (c1 >= 'A' && c1 <= 'Z') ? c1 - 'A' + 'a' : c1;
unsigned char c2 = 0;
Expand All @@ -162,7 +162,7 @@ void dontwarn5() {
c5 = (c5 >= 'A' && c5 <= 'Z') ? c5 - 'A' + 'a' : c5;
}

void dontwarn6() {
void dontwarn6(void) {
int x = ~0;
unsigned y = ~0;
}
Expand All @@ -172,11 +172,11 @@ void dontwarn7(unsigned x) {
}
}

void dontwarn8() {
void dontwarn8(void) {
unsigned x = (unsigned)-1;
}

unsigned dontwarn9() {
unsigned dontwarn9(void) {
return ~0;
}

Expand All @@ -190,7 +190,7 @@ char dontwarn10(long long x) {
// C library functions, handled via apiModeling.StdCLibraryFunctions

int isascii(int c);
void libraryFunction1() {
void libraryFunction1(void) {
char kb2[5];
int X = 1000;
if (isascii(X)) {
Expand All @@ -204,7 +204,7 @@ typedef struct FILE {} FILE; int getc(FILE *stream);
char reply_string[8192];
FILE *cin;
extern int dostuff(void);
int libraryFunction2() {
int libraryFunction2(void) {
int c, n;
int dig;
char *cp = reply_string;
Expand Down Expand Up @@ -239,7 +239,7 @@ double floating_point(long long a, int b) {
return 137;
}

double floating_point2() {
double floating_point2(void) {
int a = 1 << 24;
long long b = 1LL << 53;
float f = a; // no-warning
Expand Down
6 changes: 3 additions & 3 deletions clang/test/Analysis/copypaste/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

int global;

int foo1() {
int foo1(void) {
if (global > 0)
return 0;
else if (global < 0)
Expand All @@ -13,7 +13,7 @@ int foo1() {
}

// Different associated type (int instead of float)
int foo2() {
int foo2(void) {
if (global > 0)
return 0;
else if (global < 0)
Expand All @@ -22,7 +22,7 @@ int foo2() {
}

// Different number of associated types.
int foo3() {
int foo3(void) {
if (global > 0)
return 0;
else if (global < 0)
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void coverage9(int *x) {
y = (*x); // no warning
}

static void empty_function(){
static void empty_function(void){
}
int use_empty_function(int x) {
x = 0;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/crash-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void inlined(int x, float y) {
clang_analyzer_crash();
}

void test() {
void test(void) {
inlined(0, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/cstring-plist.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ char *strncpy(char *restrict s1, const char *restrict s2, size_t n);



void cstringchecker_bounds_nocrash() {
void cstringchecker_bounds_nocrash(void) {
char *p = malloc(2);
strncpy(p, "AAA", sizeof("AAA")); // we don't expect warning as the checker is disabled
free(p);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/cstring-ranges.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

char *strcpy(char *, const char *);

void foo() {
void foo(void) {
char *a = 0, *b = 0;
strcpy(a, b);
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Analysis/cstring-syntax-weird2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
typedef __SIZE_TYPE__ size_t;
// The last parameter is normally size_t but the test is about the abnormal
// situation when it's not a size_t.
size_t strlcpy(char *, const char *, void (*)());
size_t strlcpy(char *, const char *, void (*)(void));

void foo();
void foo(void);

void testWeirdDecls(const char *src) {
char dst[10];
Expand Down
12 changes: 6 additions & 6 deletions clang/test/Analysis/ctu-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct {
} FooBar;
extern FooBar fb;
int f(int);
void testGlobalVariable() {
void testGlobalVariable(void) {
clang_analyzer_eval(f(5) == 1); // expected-warning{{TRUE}}
}

Expand All @@ -27,14 +27,14 @@ int enumCheck(void);
enum A { x,
y,
z };
void testEnum() {
void testEnum(void) {
clang_analyzer_eval(x == 0); // expected-warning{{TRUE}}
clang_analyzer_eval(enumCheck() == 42); // expected-warning{{TRUE}}
}

// Test that asm import does not fail.
int inlineAsm();
int testInlineAsm() {
int inlineAsm(void);
int testInlineAsm(void) {
return inlineAsm();
}

Expand All @@ -47,7 +47,7 @@ void testMacro(void) {

// The external function prototype is incomplete.
// warning:implicit functions are prohibited by c99
void testImplicit() {
void testImplicit(void) {
int res = identImplicit(6); // external implicit functions are not inlined
clang_analyzer_eval(res == 6); // expected-warning{{TRUE}}
// Call something with uninitialized from the same function in which the implicit was called.
Expand All @@ -63,7 +63,7 @@ struct DataType {
int b;
};
int structInProto(struct DataType *d);
void testStructDefInArgument() {
void testStructDefInArgument(void) {
struct DataType d;
d.a = 1;
d.b = 0;
Expand Down
Loading