Skip to content

Commit e02f12f

Browse files
authored
Merge pull request #419 from opcm/macos-scan-build
Macos scan build
2 parents 11b2c63 + fa5ba24 commit e02f12f

File tree

8 files changed

+57
-21
lines changed

8 files changed

+57
-21
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Mac OS X scan-build
2+
3+
on:
4+
push:
5+
branches: [ macos-scan-build ]
6+
pull_request:
7+
branches: [ macos-scan-build ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: macos-11
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: cmake
17+
run: |
18+
rm -rf ${{ github.workspace }}/build
19+
/usr/local/opt/llvm/bin/scan-build cmake -B ${{ github.workspace }}/build -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}
20+
- name: make
21+
run: |
22+
cd ${{ github.workspace }}/build
23+
/usr/local/opt/llvm/bin/scan-build --exclude src/simdjson --status-bugs make -j

examples/c_example.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ int main(int argc, const char *argv[])
107107
printf("[c_example] PCM measurement stopped, compute result %u\n", total);
108108

109109
lcore_id = pcm_getcpu();
110-
printf("C:%lu I:%lu, IPC:%3.2f\n",
111-
PCM.pcm_c_get_cycles(lcore_id),
112-
PCM.pcm_c_get_instr(lcore_id),
110+
printf("C:%llu I:%llu, IPC:%3.2f\n",
111+
(unsigned long long)PCM.pcm_c_get_cycles(lcore_id),
112+
(unsigned long long)PCM.pcm_c_get_instr(lcore_id),
113113
(double)PCM.pcm_c_get_instr(lcore_id)/PCM.pcm_c_get_cycles(lcore_id));
114-
printf("CPU%d E0: %lu, E1: %lu, E2: %lu, E3: %lu\n",
114+
printf("CPU%d E0: %llu, E1: %llu, E2: %llu, E3: %llu\n",
115115
lcore_id,
116-
PCM.pcm_c_get_core_event(lcore_id,0),
117-
PCM.pcm_c_get_core_event(lcore_id,1),
118-
PCM.pcm_c_get_core_event(lcore_id,2),
119-
PCM.pcm_c_get_core_event(lcore_id,3));
116+
(unsigned long long)PCM.pcm_c_get_core_event(lcore_id,0),
117+
(unsigned long long)PCM.pcm_c_get_core_event(lcore_id,1),
118+
(unsigned long long)PCM.pcm_c_get_core_event(lcore_id,2),
119+
(unsigned long long)PCM.pcm_c_get_core_event(lcore_id,3));
120120

121121
return 0;
122122
}

src/MacMSRDriver/PcmMsr/PcmMsr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,11 @@ void* PcmMsrDriverClassName::mapMemory (uint32_t address, UInt8 **virtual_addres
249249

250250
IOMemoryMap *memory_map = NULL;
251251
IOMemoryDescriptor *memory_descriptor = NULL;
252-
252+
#ifndef __clang_analyzer__ // address a false-positive
253253
memory_descriptor = IOMemoryDescriptor::withPhysicalAddress(address,
254254
4096,
255255
kIODirectionInOut);
256+
#endif
256257
if (memory_descriptor) {
257258
IOReturn ioErr = memory_descriptor->prepare(kIODirectionInOut);
258259
if (ioErr == kIOReturnSuccess) {
@@ -268,9 +269,12 @@ void* PcmMsrDriverClassName::mapMemory (uint32_t address, UInt8 **virtual_addres
268269
}
269270
}
270271
else {
271-
memory_descriptor->release();
272272
IOLog("%s[%p]::%s() -- IOMemoryDescriptor::prepare() failure\n", getName(), this, __FUNCTION__);
273273
}
274+
if (!memory_map)
275+
{
276+
memory_descriptor->release();
277+
}
274278
} else {
275279
IOLog("%s[%p]::%s() -- IOMemoryDescriptor::withPhysicalAddress() failure\n", getName(), this, __FUNCTION__);
276280
}
@@ -288,7 +292,9 @@ void PcmMsrDriverClassName::unmapMemory (void *memory_map)
288292

289293
if (m_map) {
290294
m_map->getMemoryDescriptor()->complete();
295+
#ifndef __clang_analyzer__ // address a false-positive
291296
m_map->getMemoryDescriptor()->release();
297+
#endif
292298
m_map->unmap();
293299
m_map->release();
294300
}

src/MacMSRDriver/PcmMsr/PcmMsr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ class PcmMsrDriverClassName : public IOService
1010
OSDeclareDefaultStructors(com_intel_driver_PcmMsr)
1111
public:
1212
// IOService methods
13-
virtual bool start(IOService* provider);
13+
virtual bool start(IOService* provider) override;
1414

1515
virtual IOReturn writeMSR(pcm_msr_data_t* data);
1616
virtual IOReturn readMSR(pcm_msr_data_t* idata,pcm_msr_data_t* odata);
1717
virtual IOReturn buildTopology(topologyEntry* odata, uint32_t input_num_cores);
18-
virtual bool init(OSDictionary *dict);
19-
virtual void free(void);
20-
virtual bool handleOpen(IOService* forClient, IOOptionBits opts, void* args);
21-
virtual bool handleIsOpen(const IOService* forClient) const;
22-
virtual void handleClose(IOService* forClient, IOOptionBits opts);
18+
virtual bool init(OSDictionary *dict) override;
19+
virtual void free(void) override;
20+
virtual bool handleOpen(IOService* forClient, IOOptionBits opts, void* args) override;
21+
virtual bool handleIsOpen(const IOService* forClient) const override;
22+
virtual void handleClose(IOService* forClient, IOOptionBits opts) override;
2323

2424
virtual uint32_t getNumCores();
2525

src/cpucounters.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,8 @@ bool PCM::discoverSystemTopology()
10241024
return false;
10251025
}
10261026

1027+
(void) coreMaskWidth; // to supress warnings on MacOS (unused vars)
1028+
10271029
uint32 l2CacheMaskShift = 0;
10281030
#ifdef PCM_DEBUG_TOPOLOGY
10291031
uint32 threadsSharingL2;
@@ -1044,13 +1046,15 @@ bool PCM::discoverSystemTopology()
10441046
<< " [the most significant bit = " << l2CacheMaskShift << "]\n";
10451047
#endif
10461048

1049+
#ifndef __APPLE__
10471050
auto populateEntry = [&smtMaskWidth, &coreMaskWidth, &l2CacheMaskShift](TopologyEntry & entry, const int apic_id)
10481051
{
10491052
entry.thread_id = smtMaskWidth ? extract_bits_ui(apic_id, 0, smtMaskWidth - 1) : 0;
10501053
entry.core_id = (smtMaskWidth + coreMaskWidth) ? extract_bits_ui(apic_id, smtMaskWidth, smtMaskWidth + coreMaskWidth - 1) : 0;
10511054
entry.socket = extract_bits_ui(apic_id, smtMaskWidth + coreMaskWidth, 31);
10521055
entry.tile_id = extract_bits_ui(apic_id, l2CacheMaskShift, 31);
10531056
};
1057+
#endif
10541058

10551059
auto populateHybridEntry = [this](TopologyEntry& entry, int core) -> bool
10561060
{
@@ -7466,7 +7470,7 @@ void ServerPCICFGUncore::cleanupMemTest(const ServerPCICFGUncore::MemTestParam &
74667470
munmap(b, memBufferBlockSize);
74677471
#elif defined(_MSC_VER)
74687472
VirtualFree(b, memBufferBlockSize, MEM_RELEASE);
7469-
#elif defined(__FreeBSD__)
7473+
#elif defined(__FreeBSD__) || defined(__APPLE__)
74707474
(void) b; // avoid the unused variable warning
74717475
(void) memBufferBlockSize; // avoid the unused variable warning
74727476
#else

src/mmio.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ OwnMMIORange::~OwnMMIORange()
160160

161161
#include "PCIDriverInterface.h"
162162

163-
MMIORange::MMIORange(uint64 physical_address, uint64 size_, bool readonly_) :
163+
MMIORange::MMIORange(uint64 physical_address, uint64 size_, bool) :
164164
mmapAddr(NULL),
165-
size(size_),
166-
readonly(readonly_)
165+
size(size_)
167166
{
168167
if (size > 4096)
169168
{

src/mmio.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ class MMIORange
134134

135135
class MMIORange
136136
{
137+
#ifndef __APPLE__
137138
int32 fd;
139+
#endif
138140
char * mmapAddr;
139141
const uint64 size;
142+
#ifndef __APPLE__
140143
const bool readonly;
144+
#endif
141145
public:
142146
MMIORange(uint64 baseAddr_, uint64 size_, bool readonly_ = true);
143147
uint32 read32(uint64 offset);

tests/daemon_alignment_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void checkAlignment(char const * debugMessage, void* ptr)
1414
if(currentAlignment != 0)
1515
{
1616
printf("Failed\n");
17-
printf("Current alignment: %lu\n\n", currentAlignment);
17+
printf("Current alignment: %llu\n\n", (unsigned long long)currentAlignment);
1818
exit(EXIT_FAILURE);
1919
}
2020
else

0 commit comments

Comments
 (0)