Skip to content

Commit 325a49f

Browse files
author
Hal Finkel
committed
characters are always array... the default length is 1
1 parent 5626409 commit 325a49f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/Parse/ParseDecl.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "lfort/Parse/Parser.h"
1515
#include "RAIIObjectsForParser.h"
16+
#include "lfort/AST/ASTContext.h"
1617
#include "lfort/Basic/AddressSpaces.h"
1718
#include "lfort/Basic/OpenCL.h"
1819
#include "lfort/Basic/TargetInfo.h"
@@ -3355,6 +3356,7 @@ void Parser::ParseDeclarationTypeSpec(DeclSpec &DS,
33553356
break; }
33563357
case tok::kw_character: {
33573358
DeclSpec::TST T = DeclSpec::TST_char;
3359+
bool LenProvided = false;
33583360
if (NextToken().isInLine(tok::l_paren) || NextToken().isInLine(tok::star)) {
33593361
bool OldStyle = NextToken().isInLine(tok::star);
33603362
unsigned KindValue;
@@ -3386,11 +3388,23 @@ void Parser::ParseDeclarationTypeSpec(DeclSpec &DS,
33863388
}
33873389

33883390
if (!LenValueLoc.isInvalid()) {
3391+
LenProvided = true;
33893392
DeclaratorChunks.push_back(DeclaratorChunk::getArray(0, false, 0,
33903393
LenValue.release(), LenValueLoc, LenValueLoc));
33913394
}
33923395
}
33933396

3397+
// The default length is 1.
3398+
if (!LenProvided) {
3399+
QualType SizeTy = Actions.getASTContext().getSizeType();
3400+
unsigned SizeSize = Actions.getASTContext().getTypeSize(SizeTy);
3401+
DeclaratorChunks.push_back(DeclaratorChunk::getArray(0, false, 0,
3402+
IntegerLiteral::Create(Actions.getASTContext(),
3403+
llvm::APInt(SizeSize, 1),
3404+
SizeTy, SourceLocation()),
3405+
Loc, Loc));
3406+
}
3407+
33943408
isInvalid |= DS.SetTypeSpecType(T, Loc, PrevSpec, DiagID);
33953409
break; }
33963410
// FIXME: everything else

test/CodeGen/decl.F90

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ program hello
5252
! CHECK: %i6 = alloca i64, align 8
5353
character c
5454
character(kind = 4) c2
55-
! CHECK: %c = alloca i8, align 1
56-
! CHECK: %c2 = alloca i32, align 4
55+
! CHECK: %c = alloca [1 x i8], align 1
56+
! CHECK: %c2 = alloca [1 x i32], align 4
5757
character*3 c3
5858
character*4, c4
5959
character*(2+3) c5

0 commit comments

Comments
 (0)