Bug Summary

File:root/firefox-clang/intl/icu/source/i18n/dtptngen_impl.h
Warning:line 113, column 16
Excessive padding in 'struct icu_77::dtTypeElem' (4 padding bytes, where 0 is optimal). Optimal fields order: field, patternChar, type, minLen, weight, consider reordering the fields or adding explicit padding members

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name dtptngen.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -resource-dir /usr/lib/llvm-21/lib/clang/21 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D _GLIBCXX_ASSERTIONS -D DEBUG=1 -D U_I18N_IMPLEMENTATION -D _LIBCPP_DISABLE_DEPRECATION_WARNINGS -D U_USING_ICU_NAMESPACE=0 -D U_NO_DEFAULT_INCLUDE_UTF_HEADERS=1 -D U_HIDE_OBSOLETE_UTF_OLD_H=1 -D UCONFIG_NO_LEGACY_CONVERSION -D UCONFIG_NO_TRANSLITERATION -D UCONFIG_NO_REGULAR_EXPRESSIONS -D UCONFIG_NO_BREAK_ITERATION -D UCONFIG_NO_IDNA -D UCONFIG_NO_MF2 -D U_CHARSET_IS_UTF8 -D UNISTR_FROM_CHAR_EXPLICIT=explicit -D UNISTR_FROM_STRING_EXPLICIT=explicit -D U_ENABLE_DYLOAD=0 -D U_DEBUG=1 -I /root/firefox-clang/config/external/icu/i18n -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/config/external/icu/i18n -I /root/firefox-clang/intl/icu/source/common -I /root/firefox-clang/mfbt/double-conversion -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-deprecated-this-capture -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-comma -Wno-implicit-const-int-float-conversion -Wno-macro-redefined -Wno-microsoft-include -Wno-tautological-unsigned-enum-zero-compare -Wno-unreachable-code-loop-increment -Wno-unreachable-code-return -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2025-06-30-093548-1913035-1 -x c++ /root/firefox-clang/intl/icu/source/i18n/dtptngen.cpp
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
3/*
4*******************************************************************************
5* Copyright (C) 2007-2016, International Business Machines Corporation and
6* others. All Rights Reserved.
7*******************************************************************************
8*
9* File DTPTNGEN.H
10*
11*******************************************************************************
12*/
13
14#ifndef __DTPTNGEN_IMPL_H__
15#define __DTPTNGEN_IMPL_H__
16
17#include "unicode/udatpg.h"
18
19#include "unicode/strenum.h"
20#include "unicode/unistr.h"
21#include "uvector.h"
22
23// TODO(claireho): Split off Builder class.
24// TODO(claireho): If splitting off Builder class: As subclass or independent?
25
26#define MAX_PATTERN_ENTRIES52 52
27#define MAX_CLDR_FIELD_LEN60 60
28#define MAX_DT_TOKEN50 50
29#define MAX_RESOURCE_FIELD12 12
30#define MAX_AVAILABLE_FORMATS12 12
31#define NONE0 0
32#define EXTRA_FIELD0x10000 0x10000
33#define MISSING_FIELD0x1000 0x1000
34#define MAX_STRING_ENUMERATION200 200
35#define SINGLE_QUOTE((char16_t)0x0027) ((char16_t)0x0027)
36#define FORWARDSLASH((char16_t)0x002F) ((char16_t)0x002F)
37#define BACKSLASH((char16_t)0x005C) ((char16_t)0x005C)
38#define SPACE((char16_t)0x0020) ((char16_t)0x0020)
39#define QUOTATION_MARK((char16_t)0x0022) ((char16_t)0x0022)
40#define ASTERISK((char16_t)0x002A) ((char16_t)0x002A)
41#define PLUSSITN((char16_t)0x002B) ((char16_t)0x002B)
42#define COMMA((char16_t)0x002C) ((char16_t)0x002C)
43#define HYPHEN((char16_t)0x002D) ((char16_t)0x002D)
44#define DOT((char16_t)0x002E) ((char16_t)0x002E)
45#define COLON((char16_t)0x003A) ((char16_t)0x003A)
46#define CAP_A((char16_t)0x0041) ((char16_t)0x0041)
47#define CAP_B((char16_t)0x0042) ((char16_t)0x0042)
48#define CAP_C((char16_t)0x0043) ((char16_t)0x0043)
49#define CAP_D((char16_t)0x0044) ((char16_t)0x0044)
50#define CAP_E((char16_t)0x0045) ((char16_t)0x0045)
51#define CAP_F((char16_t)0x0046) ((char16_t)0x0046)
52#define CAP_G((char16_t)0x0047) ((char16_t)0x0047)
53#define CAP_H((char16_t)0x0048) ((char16_t)0x0048)
54#define CAP_J((char16_t)0x004A) ((char16_t)0x004A)
55#define CAP_K((char16_t)0x004B) ((char16_t)0x004B)
56#define CAP_L((char16_t)0x004C) ((char16_t)0x004C)
57#define CAP_M((char16_t)0x004D) ((char16_t)0x004D)
58#define CAP_O((char16_t)0x004F) ((char16_t)0x004F)
59#define CAP_Q((char16_t)0x0051) ((char16_t)0x0051)
60#define CAP_S((char16_t)0x0053) ((char16_t)0x0053)
61#define CAP_T((char16_t)0x0054) ((char16_t)0x0054)
62#define CAP_U((char16_t)0x0055) ((char16_t)0x0055)
63#define CAP_V((char16_t)0x0056) ((char16_t)0x0056)
64#define CAP_W((char16_t)0x0057) ((char16_t)0x0057)
65#define CAP_X((char16_t)0x0058) ((char16_t)0x0058)
66#define CAP_Y((char16_t)0x0059) ((char16_t)0x0059)
67#define CAP_Z((char16_t)0x005A) ((char16_t)0x005A)
68#define LOWLINE((char16_t)0x005F) ((char16_t)0x005F)
69#define LOW_A((char16_t)0x0061) ((char16_t)0x0061)
70#define LOW_B((char16_t)0x0062) ((char16_t)0x0062)
71#define LOW_C((char16_t)0x0063) ((char16_t)0x0063)
72#define LOW_D((char16_t)0x0064) ((char16_t)0x0064)
73#define LOW_E((char16_t)0x0065) ((char16_t)0x0065)
74#define LOW_F((char16_t)0x0066) ((char16_t)0x0066)
75#define LOW_G((char16_t)0x0067) ((char16_t)0x0067)
76#define LOW_H((char16_t)0x0068) ((char16_t)0x0068)
77#define LOW_I((char16_t)0x0069) ((char16_t)0x0069)
78#define LOW_J((char16_t)0x006A) ((char16_t)0x006A)
79#define LOW_K((char16_t)0x006B) ((char16_t)0x006B)
80#define LOW_L((char16_t)0x006C) ((char16_t)0x006C)
81#define LOW_M((char16_t)0x006D) ((char16_t)0x006D)
82#define LOW_N((char16_t)0x006E) ((char16_t)0x006E)
83#define LOW_O((char16_t)0x006F) ((char16_t)0x006F)
84#define LOW_P((char16_t)0x0070) ((char16_t)0x0070)
85#define LOW_Q((char16_t)0x0071) ((char16_t)0x0071)
86#define LOW_R((char16_t)0x0072) ((char16_t)0x0072)
87#define LOW_S((char16_t)0x0073) ((char16_t)0x0073)
88#define LOW_T((char16_t)0x0074) ((char16_t)0x0074)
89#define LOW_U((char16_t)0x0075) ((char16_t)0x0075)
90#define LOW_V((char16_t)0x0076) ((char16_t)0x0076)
91#define LOW_W((char16_t)0x0077) ((char16_t)0x0077)
92#define LOW_X((char16_t)0x0078) ((char16_t)0x0078)
93#define LOW_Y((char16_t)0x0079) ((char16_t)0x0079)
94#define LOW_Z((char16_t)0x007A) ((char16_t)0x007A)
95#define DT_NARROW-0x101 -0x101
96#define DT_SHORTER-0x102 -0x102
97#define DT_SHORT-0x103 -0x103
98#define DT_LONG-0x104 -0x104
99#define DT_NUMERIC0x100 0x100
100#define DT_DELTA0x10 0x10
101
102U_NAMESPACE_BEGINnamespace icu_77 {
103
104const int32_t UDATPG_FRACTIONAL_MASK = 1<<UDATPG_FRACTIONAL_SECOND_FIELD;
105const int32_t UDATPG_SECOND_AND_FRACTIONAL_MASK = (1<<UDATPG_SECOND_FIELD) | (1<<UDATPG_FRACTIONAL_SECOND_FIELD);
106
107typedef enum dtStrEnum {
108 DT_BASESKELETON,
109 DT_SKELETON,
110 DT_PATTERN
111}dtStrEnum;
112
113typedef struct dtTypeElem {
Excessive padding in 'struct icu_77::dtTypeElem' (4 padding bytes, where 0 is optimal). Optimal fields order: field, patternChar, type, minLen, weight, consider reordering the fields or adding explicit padding members
114 char16_t patternChar;
115 UDateTimePatternField field;
116 int16_t type;
117 int16_t minLen;
118 int16_t weight;
119} dtTypeElem;
120
121// A compact storage mechanism for skeleton field strings. Several dozen of these will be created
122// for a typical DateTimePatternGenerator instance.
123class SkeletonFields : public UMemory {
124public:
125 SkeletonFields();
126 void clear();
127 void copyFrom(const SkeletonFields& other);
128 void clearField(int32_t field);
129 char16_t getFieldChar(int32_t field) const;
130 int32_t getFieldLength(int32_t field) const;
131 void populate(int32_t field, const UnicodeString& value);
132 void populate(int32_t field, char16_t repeatChar, int32_t repeatCount);
133 UBool isFieldEmpty(int32_t field) const;
134 UnicodeString& appendTo(UnicodeString& string) const;
135 UnicodeString& appendFieldTo(int32_t field, UnicodeString& string) const;
136 char16_t getFirstChar() const;
137 inline bool operator==(const SkeletonFields& other) const;
138 inline bool operator!=(const SkeletonFields& other) const;
139
140private:
141 int8_t chars[UDATPG_FIELD_COUNT];
142 int8_t lengths[UDATPG_FIELD_COUNT];
143};
144
145inline bool SkeletonFields::operator==(const SkeletonFields& other) const {
146 return (uprv_memcmp(chars, other.chars, sizeof(chars)):: memcmp(chars, other.chars,sizeof(chars)) == 0
147 && uprv_memcmp(lengths, other.lengths, sizeof(lengths)):: memcmp(lengths, other.lengths,sizeof(lengths)) == 0);
148}
149
150inline bool SkeletonFields::operator!=(const SkeletonFields& other) const {
151 return (! operator==(other));
152}
153
154class PtnSkeleton : public UMemory {
155public:
156 int32_t type[UDATPG_FIELD_COUNT];
157 SkeletonFields original;
158 SkeletonFields baseOriginal;
159 UBool addedDefaultDayPeriod;
160
161 PtnSkeleton();
162 PtnSkeleton(const PtnSkeleton& other);
163 void copyFrom(const PtnSkeleton& other);
164 void clear();
165 UBool equals(const PtnSkeleton& other) const;
166 UnicodeString getSkeleton() const;
167 UnicodeString getBaseSkeleton() const;
168 char16_t getFirstChar() const;
169
170 // TODO: Why is this virtual, as well as the other destructors in this file? We don't want
171 // vtables when we don't use class objects polymorphically.
172 virtual ~PtnSkeleton();
173};
174
175class PtnElem : public UMemory {
176public:
177 UnicodeString basePattern;
178 LocalPointer<PtnSkeleton> skeleton;
179 UnicodeString pattern;
180 UBool skeletonWasSpecified; // if specified in availableFormats, not derived
181 LocalPointer<PtnElem> next;
182
183 PtnElem(const UnicodeString &basePattern, const UnicodeString &pattern);
184 virtual ~PtnElem();
185};
186
187class FormatParser : public UMemory {
188public:
189 UnicodeString items[MAX_DT_TOKEN50];
190 int32_t itemNumber;
191
192 FormatParser();
193 virtual ~FormatParser();
194 void set(const UnicodeString& patternString);
195 void getQuoteLiteral(UnicodeString& quote, int32_t *itemIndex);
196 UBool isPatternSeparator(const UnicodeString& field) const;
197 static UBool isQuoteLiteral(const UnicodeString& s);
198 static int32_t getCanonicalIndex(const UnicodeString& s) { return getCanonicalIndex(s, true); }
199 static int32_t getCanonicalIndex(const UnicodeString& s, UBool strict);
200
201private:
202 typedef enum TokenStatus {
203 START,
204 ADD_TOKEN,
205 SYNTAX_ERROR,
206 DONE
207 } TokenStatus;
208
209 TokenStatus status;
210 virtual TokenStatus setTokens(const UnicodeString& pattern, int32_t startPos, int32_t *len);
211};
212
213class DistanceInfo : public UMemory {
214public:
215 int32_t missingFieldMask;
216 int32_t extraFieldMask;
217
218 DistanceInfo() {}
219 virtual ~DistanceInfo();
220 void clear() { missingFieldMask = extraFieldMask = 0; }
221 void setTo(const DistanceInfo& other);
222 void addMissing(int32_t field) { missingFieldMask |= (1<<field); }
223 void addExtra(int32_t field) { extraFieldMask |= (1<<field); }
224};
225
226class DateTimeMatcher: public UMemory {
227public:
228 PtnSkeleton skeleton;
229
230 void getBasePattern(UnicodeString& basePattern);
231 UnicodeString getPattern();
232 void set(const UnicodeString& pattern, FormatParser* fp);
233 void set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeleton);
234 void copyFrom(const PtnSkeleton& skeleton);
235 void copyFrom();
236 PtnSkeleton* getSkeletonPtr();
237 UBool equals(const DateTimeMatcher* other) const;
238 int32_t getDistance(const DateTimeMatcher& other, int32_t includeMask, DistanceInfo& distanceInfo) const;
239 DateTimeMatcher();
240 DateTimeMatcher(const DateTimeMatcher& other);
241 DateTimeMatcher& operator=(const DateTimeMatcher& other);
242 virtual ~DateTimeMatcher();
243 int32_t getFieldMask() const;
244};
245
246class PatternMap : public UMemory {
247public:
248 PtnElem *boot[MAX_PATTERN_ENTRIES52];
249 PatternMap();
250 virtual ~PatternMap();
251 void add(const UnicodeString& basePattern, const PtnSkeleton& skeleton, const UnicodeString& value, UBool skeletonWasSpecified, UErrorCode& status);
252 const UnicodeString* getPatternFromBasePattern(const UnicodeString& basePattern, UBool& skeletonWasSpecified) const;
253 const UnicodeString* getPatternFromSkeleton(const PtnSkeleton& skeleton, const PtnSkeleton** specifiedSkeletonPtr = nullptr) const;
254 void copyFrom(const PatternMap& other, UErrorCode& status);
255 PtnElem* getHeader(char16_t baseChar) const;
256 UBool equals(const PatternMap& other) const;
257private:
258 UBool isDupAllowed;
259 PtnElem* getDuplicateElem(const UnicodeString& basePattern, const PtnSkeleton& skeleton, PtnElem *baseElem);
260}; // end PatternMap
261
262class PatternMapIterator : public UMemory {
263public:
264 PatternMapIterator(UErrorCode &status);
265 virtual ~PatternMapIterator();
266 void set(PatternMap& patternMap);
267 PtnSkeleton* getSkeleton() const;
268 UBool hasNext() const;
269 DateTimeMatcher& next();
270private:
271 int32_t bootIndex;
272 PtnElem *nodePtr;
273 LocalPointer<DateTimeMatcher> matcher;
274 PatternMap *patternMap;
275};
276
277class DTSkeletonEnumeration : public StringEnumeration {
278public:
279 DTSkeletonEnumeration(PatternMap& patternMap, dtStrEnum type, UErrorCode& status);
280 virtual ~DTSkeletonEnumeration();
281 static UClassID U_EXPORT2 getStaticClassID();
282 virtual UClassID getDynamicClassID() const override;
283 virtual const UnicodeString* snext(UErrorCode& status) override;
284 virtual void reset(UErrorCode& status) override;
285 virtual int32_t count(UErrorCode& status) const override;
286private:
287 int32_t pos;
288 UBool isCanonicalItem(const UnicodeString& item);
289 LocalPointer<UVector> fSkeletons;
290};
291
292class DTRedundantEnumeration : public StringEnumeration {
293public:
294 DTRedundantEnumeration();
295 virtual ~DTRedundantEnumeration();
296 static UClassID U_EXPORT2 getStaticClassID();
297 virtual UClassID getDynamicClassID() const override;
298 virtual const UnicodeString* snext(UErrorCode& status) override;
299 virtual void reset(UErrorCode& status) override;
300 virtual int32_t count(UErrorCode& status) const override;
301 void add(const UnicodeString &pattern, UErrorCode& status);
302private:
303 int32_t pos;
304 UBool isCanonicalItem(const UnicodeString& item) const;
305 LocalPointer<UVector> fPatterns;
306};
307
308U_NAMESPACE_END}
309
310#endif